なぜTomcatがJSPページをレンダリングしないのですか?場合、私は、サーブレットコンテナのURLに言っている:(コントローラがGETハンドル以降 - 要求)それよりもhttp://localhost:8080/contacts
はすべての権利だが、私は直接Tomcatに伝えるたびどこもらうよりも、プロジェクト内のJSP物理的http://localhost:8080/WEB-INF/views/list.jsp
あるTomcatがJSPページをレンダリングしない
404エラー
これのIntelliJ IDEAプロジェクト構造は次のとおりです。
マイpom.xml
:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<!--support @Service, @Repository -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<!-- teg library -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
</dependencies>
コントローラー:
@Controller
@RequestMapping("/contacts")
public class ContactController {
@RequestMapping(method = RequestMethod.GET)
public String list(Model model) {
return "list";
}
}
JSP:
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%--
Created by IntelliJ IDEA.
User: Игорь
Date: 07.10.2017
Time: 13:18
To change this template use File | Settings | File Templates.
--%>
<html>
<head>
<title>Title</title>
</head>
<body>
<% System.out.println("Inside JSP file!!!!!!!!!!!!!!!!!!!"); %>
<h1>Contact Listing</h1>
SOME MESSAGE!
</body>
</html>
'@RequestMapping( "/ contacts")'は、Webアプリケーションルートの場所をTomcatに通知します。 'WEB-INF/views'はサーブレットマッピングの一部ではないので、Tomcatはlist.jspを取得できません。 –
@dsp_userここで言うことは、いくつかのレベルで間違っています。 '@RequestMapping("/contacts ")'はSpringのサーブレットに着信要求をいつこのコントローラに送るかを指示します。 '/ contacts'はWebアプリケーションルート+ SpringサーブレットのマッピングURLパターンに対する相対パスです。アプリケーションルート自体ではありません。すなわち '/spring-servlet-mapping/contacts' –