[英]the redirected page is not being displayed in spring-mvc ajax GET request
單擊按鈕后,我將網頁重定向到另一個網頁。 但是重定向的頁面無法打開,並且我收到以下錯誤消息: 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>
爪哇
@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"
});
}
嘗試在ajax調用中傳遞完整路徑
url : "/UserTest/redirect" // here
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.