英文:
Page is not loading on spring boot
问题
我正在尝试构建一个Spring Boot应用程序,但在加载JSP页面时显示404错误。我正在使用Jasper来加载JSP,以下是我的代码。
主文件
@SpringBootApplication
public class SpringAppApplication {
public static void main(String[] args) {
SpringApplication.run(SpringAppApplication.class, args);
}
}
控制器文件
@Controller
public class ApplicationController {
@RequestMapping("home")
public String home() {
return "index";
}
}
属性文件
server.port=8000
spring.mvc.view.suffix=.jsp
spring.mvc.view.prefix=/WEB-INF/pages/
依赖项
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.38</version>
</dependency>
</dependencies>
当我运行应用程序并访问 http://localhost:8000/home
时,出现 404
错误。如何解决这个问题?
英文:
I'm trying to build a spring boot application and when i load a jsp page it shows 404 error
i'm using jasper to load the jsp below is my code
Main File
@SpringBootApplication
public class SpringAppApplication {
public static void main(String[] args) {
SpringApplication.run(SpringAppApplication.class, args);
}
}
controller file
@Controller
public class ApplicationController {
@RequestMapping("home")
public String home() {
return "index";
}
}
properties file
server.port=8000
spring.mvc.view.suffix=.jsp
spring.mvc.view.prefix=/WEB-INF/pages/
dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.38</version>
</dependency>
</dependencies>
when i run the app and access http://localhost:8000/home
gives me a 404
How to solve this issue?
答案1
得分: 0
你把WEB-INF
文件夹放在项目结构的哪里?WEB-INF
的正确放置位置是:
src/main/webapp/WEB-INF/jsp
请参考此答案:https://stackoverflow.com/a/45685114/2614885
英文:
Where have you placed your WEB-INF
folder in project structure? The correct placement of WEB-INF
is
src/main/webapp/WEB-INF/jsp
Please refer this answer https://stackoverflow.com/a/45685114/2614885
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论