這裏是我的web.xml:問題帶彈簧的錯誤頁面和web.xml
<error-page>
<error-code>404</error-code>
<location>/error/404</location>
</error-page>
下面是我的控制器類:
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
@RequestMapping(value = "/error")
@Controller
public class ErrorController {
@RequestMapping(value = {"/307", "/400", "/401", "/403", "/404", "/405", "500", "503"})
public ModelAndView error(HttpServletRequest request) throws Exception {
String path = request.getServletPath().replace("/error/", "");
return new ModelAndView("redirect:/error/view/"+path);
}
如果我請求錯誤的URL這樣
http://localhost:8080/erro/
它顯示404錯誤頁面,但它更改網址
http://localhost:8080/error/view/404
如果請求了無效的URL,則會顯示錯誤頁面,但舊URL已更改。我需要解決什麼問題,以便舊網址不會更改,只出現錯誤頁面?
謝謝:)
可能重複[Spring錯誤頁面無重定向](http://stackoverflow.com/questions/21096572/spring-error-page-without-redirect) –