Я пытаюсь развернуть веб-приложение Spring MVC.Я хочу перенаправить свой index.jsp в другой .jsp, но я получаю эту ошибку.
HTTP Status 404 – Not Found
--------------------------------------------------------------------------------
Type Status Report
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Мой проект Struture:
- src / main / java
- com.example.beans
- com.example.controller
- com.example.dao
- src / main / webapp /
- WEB-INF
- / jsp
- spring-servlet.xml
- web.xml
- index.jsp
spring-servlet.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">
<!-- Provide support for component scanning -->
<context:component-scan
base-package="com.example />
<!--Provide support for conversion, formatting and validation -->
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**"
location="/resources/" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="ds"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver"></property>
<property name="url"
value="jdbc:mysql://localhost:3306/dbexample></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"></property>
</bean>
<bean id="dao" class="com.example.dao.ObjectDao">
<property name="template" ref="jt"></property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Example</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Контроллер
@Controller
public class MainController {
@RequestMapping("hello")
public String redirect() {
return "viewpage";
}
@RequestMapping("/")
public String display() {
return "index";
}
@RequestMapping("test")
public String test() {
return "test";
}
index.jsp
<html>
<body>
<h2>Hello World!</h2>
<a href="test">View test</a>
<a href="hello">Click here...</a>
</body>
</html>
Когда я нажимаю на тест, я получаю эту ошибку в журнале sts:
org.springframework.web.servlet.DispatcherServlet noHandlerFound ПРЕДУПРЕЖДЕНИЕ: нет сопоставления для GET / example / hello