Я хочу начать работу с Spring MVC, но не могу настроить простой пример. Я хочу, чтобы просто передать одну форму один параметр JSP к другому, но есть ошибка:HTTP Status 404 Spring MVC Параметры прохождения
HTTP Status 404 - /controller/results.jsp type Status report message /controller/results.jsp description The requested resource (/controller/results.jsp) is not available. Apache Tomcat/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>
Servlet-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";
}
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>
Home.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>
Спасибо.
попытаться cahange отображение на/* URL-шаблон>, в вашем случае, после того, как отправить URL не обрабатывается с Spring MVC, и вы получите ошибку –
Огромное спасибо Георгию для помощи. Правильно, когда я меняю его, похоже, что это работа. Просто я запутался в том, что такое url-шаблон для .. Я думал, что по умолчанию это мой запрос, когда я делаю Run on Server, и это suppouse, чтобы использовать этот url-шаблон, чтобы направить меня на мой первый метод RequestMapping. Но как я могу сделать действие между двумя страницами, используя форму. что я делаю, ставится http: // localhost: 8080/controller/result? firstname = hello, и он идет на мой jsp, но я хочу использовать действие с одной страницы на другую. –