Spring MVC で作業を開始したいのですが、単純な例を調整できません。あるjspから別のjspに1つのパラメーターを渡したいだけですが、エラーがあります:
HTTP ステータス 404 - /controller/results.jsp タイプ ステータス レポート メッセージ /controller/results.jsp 説明 要求されたリソース (/controller/results.jsp) は利用できません。アパッチ トムキャット/7.0.12
私の web.xml コード:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/home</url-pattern>
</servlet-mapping>
サーブレット-context.xml
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="edu.demidov.controller" />
</beans:beans>
コントローラー.java
@Controller
public class HomeController extends HttpServlet{
private static final long serialVersionUID = 4825408935018763217L;
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
EducationDaoInterface educationDaoIntfc;
@RequestMapping(value="/home", method=RequestMethod.GET)
public ModelAndView firstActionPage() {
return new ModelAndView("home");
}
@RequestMapping(value = "/result.jsp", method=RequestMethod.GET)
public String SecondActionPage(@RequestParam String firstname, Model model) throws IOException {
model.addAttribute("myname", firstname);
return "result";
}
結果.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
Hello form result.jsp
First name: ${myname}
</body>
</html>
ホーム.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form name="myform" action="<c:url value="/results.jsp"/>" method="GET">
<input type="text" name="firstname"/>
<input type="submit"/>
</form>
</body>
</html>
ありがとう。