页面在Spring Boot上无法加载。

huangapple go评论83阅读模式
英文:

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(&quot;home&quot;)
    public String home() {
        return &quot;index&quot;;
    }
}

properties file

server.port=8000
spring.mvc.view.suffix=.jsp
spring.mvc.view.prefix=/WEB-INF/pages/

dependencies

    &lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-jersey&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web-services&lt;/artifactId&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
			&lt;artifactId&gt;tomcat-jasper&lt;/artifactId&gt;
			&lt;version&gt;9.0.38&lt;/version&gt;
		&lt;/dependency&gt;
    &lt;/dependencies&gt;

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

huangapple
  • 本文由 发表于 2020年9月21日 21:23:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63993194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定