Некорректный URL
Имеется простейшее Spring MVC приложение. При переходе с first-view.jsp на ask-emp-details-view.jsp и с ask-emp-details-view.jsp на show-emp-details-view.jsp Tomcat выдает ошибку:
Я так понял неправильно прописывается URL. Но в чём причина и как её исправить?
applicationContext.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="ru.badziy.spring.mvc" />
<mvc:annotation-driven/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>spring-course-mvc</display-name>
<absolute-ordering />
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
MyController.java
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("/employee")
public class MyController {
@RequestMapping("/")
public String showFirstView() {
return "first-view";
}
@RequestMapping("/askDetails")
public String askEmployeeDetails() {
return "ask-emp-details-view";
}
@RequestMapping("/showDetails")
public String showEmpDetails(@RequestParam("employeeName") String empName, Model model) {
empName = "Mr. " + empName + "!";
model.addAttribute("nameAttribute", empName);
return "show-emp-details-view";
}
}
first-view.jsp
<!DOCTYPE html>
<html>
<body>
<h2>I wish you luck in Spring MVC learning!!!</h2>
<br>
<br>
<br>
<a href="/askDetails">Please write your details</a>
</body>
</html>
ask-emp-details-view.jsp
<!DOCTYPE html>
<html>
<body>
<h2>Dear employee, Please enter you details</h2>
<br>
<br>
<form action="/showDetails" method="get">
<input type="text" name="employeeName"
placeholder="Write your name"/>
<input type="submit"/>
</form>
</body>
</html>
show-emp-details-view.jsp
<!DOCTYPE html>
<html>
<body>
<h2>Dear employee, you are WELCOME!!!</h2>
<br>
<br>
<br>
<!--Your name: ${param.employeeName}-->
Your name: ${nameAttribute}
</body>
</html>
