Spring Boot项目URL在Chrome异常下载,IE可正常访问问题排查
Hey there, let's figure out why Chrome's prompting a download when you hit http://localhost:9082/beautysalon/ while IE runs your Spring Boot project just fine. Based on your project structure (static assets in static, JSPs in webapp/view), here are the most probable causes and fixes to try:
1. Incorrect Content-Type Response Header
Chrome enforces proper Content-Type headers way more strictly than IE. If your server sends the root path response with a header like application/octet-stream instead of text/html, Chrome will immediately treat it as a downloadable file. This usually happens when your view resolver isn't set up correctly to render JSPs—so Spring Boot is sending raw, unprocessed content instead of parsed HTML.
Double-check your application.properties for the right view configuration:
spring.mvc.view.prefix=/view/ spring.mvc.view.suffix=.jsp
Also, make sure your controller method handling the /beautysalon/ path returns a valid view name that maps to your JSP file in webapp/view (not a raw byte stream or direct response).
2. Missing JSP Dependencies
Spring Boot's embedded Tomcat doesn't come with JSP support by default. IE might be leaning on some legacy caching or lenient behavior, but Chrome rejects unprocessed JSP content as a download. You need to add the necessary dependencies to let Spring Boot compile and render JSPs:
If you're using Maven, add these to your pom.xml:
<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency>
For Gradle, add:
implementation 'javax.servlet:jstl' providedRuntime 'org.apache.tomcat.embed:tomcat-embed-jasper'
3. Static Resource Routing Conflict
Spring Boot's default static resource mapping might be overriding your JSP view for the root path. If there's an index.html in your static folder, Chrome might be trying to serve that but with a messed-up MIME type. If there's no index file, the server could be returning a raw directory listing that Chrome interprets as a download.
Fix this by explicitly mapping the /beautysalon/ path in your controller to your JSP view, instead of relying on Spring's default static resource handling.
4. Chrome's Strict MIME Sniffing
Chrome has tighter MIME sniffing rules compared to IE. Even if the Content-Type is set to text/html, if the content doesn't match (like invalid HTML, unexpected binary data, or malformed JSP output), Chrome might override the header and trigger a download.
Validate your JSP to ensure it's well-formed HTML, and check that there are no unintended byte streams or encoding issues in the response. You can use Chrome's DevTools (Network tab) to inspect the response headers and content to confirm this.
内容的提问来源于stack exchange,提问作者Jhon Smith

