希望のJSPをロードできますが、コントローラはjspで動作しません。また、何らかの理由で、web.xml/servletConfigファイルがマップされているようなフォルダ構成にjspを配置すると、jspにアクセスできなくなります。しかし、jspファイルをwebappフォルダに置くと、私はそれにアクセスすることができます。コントローラが正しく機能していませんSpring MVC
のweb.xml
<servlet>
<servlet-name>projectHub</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/projectHub-servletConfig.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>projectHub</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
projectHub-servletConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.projectHub.controllers"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="WEB-INF/jsp/" p:suffix=".jsp" />
</beans>
コントローラ
package com.projectHub.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class ProjectHubController {
//http://localhost:8080/projectHub/homepage.html
@RequestMapping(value="/homepage")
public String getHomepage(Model model) {
model.addAttribute("titleHomepage", "ProjectHub");
return "homepage";
}
}
homepage.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ProjectHub Homepage</title>
</head>
<body>
<h1>${titleHomepage}</h1>
<p>WTF</p>
</body>
</html>
フォルダ構造のイメージ:http://imgur.com/Gv75lwz
あなたのhomePage.jspはどこにありますか?あなたのディレクトリ構造を表示 –
ディレクトリ構造の画像リンクを追加 – TheDeveloper