我在点击按钮时将网页重定向到另一个网页。但重定向的页面无法打开,我收到错误No mapping found for HTTP request with URI ['UserTest/redirect/npage']
。但是,此路径有效,并在我的项目中定义。 npage.jsp文件/页面也存在于视图文件夹中。那么问题是什么以及为什么没有达到此页面? 我已经探讨了许多类似的问题,但没有一个对我有用。因此,请帮忙。
的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/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.4">
<display-name>User Test</display-name>
<servlet>
<servlet-name>UserTest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>UserTest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
UserTest-servlet.xml中:
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package = "com.test" />
<bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/WEB-INF/view/" />
<property name = "suffix" value = ".jsp" />
</bean>
</beans>
JAVA
@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public String redirect() {
return "redirect:npage";
}
@RequestMapping(value = "/npage", method = RequestMethod.GET)
public String finalPage() {
return "npage";
}
AJAX
function nopg() {
$.ajax({
type : "GET",
url : "/UserTest/redirect"
});
}
答案 0 :(得分:0)
尝试在ajax调用中传递完整路径
url : "/UserTest/redirect" // here