Java 重定向时未找到URI为的HTTP请求的映射
我已注册以下ViewResolver:Java 重定向时未找到URI为的HTTP请求的映射,java,jsp,spring-mvc,redirect,custom-error-pages,Java,Jsp,Spring Mvc,Redirect,Custom Error Pages,我已注册以下ViewResolver: <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/pages/</value> </pro
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
执行以下方法时,我会看到以下日志:
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/errorPage] in DispatcherServlet with name 'appServlet'
名为errorPage.jsp的页面位于页面文件夹下:
请解释我错在哪里?您正在重定向到URL“/errorPage”,但没有/errorPage
的请求映射。您可以添加具有该请求映射的控制器,例如:
@Controller
public class ErrorPageController {
@RequestMapping("/errorPage")
@ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR)
public String showErrorPage(){
return "errorPage";
}
}
或者,您可以只显示异常处理程序中的错误页面,而不是重定向
@ExceptionHandler(value = Exception.class)
@ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR)
public String handleException(Exception e){
return "errorPage";
}
我只能重定向到控制器方法?
@ExceptionHandler(value = Exception.class)
@ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR)
public String handleException(Exception e){
return "errorPage";
}