的web.xml
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/views/errorPages/500.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/WEB-INF/views/errorPages/error.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/WEB-INF/views/errorPages/500.jsp</location>
</error-page>
彈簧的context.xml
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">error</prop>
</props>
</property>
</bean>
<bean id="exceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="com.company.server.exception.GenericException">GenericExceptionPage</prop>
<prop key="java.lang.Exception">error</prop>
</props>
</property>
<property name="defaultErrorView" value="defaulterror"></property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
GenericException.java
public class GenericException extends RuntimeException
{
private static final long serialVersionUID = 1L;
private String customMsg;
public String message;
public String getCustomMsg()
{
return customMsg;
}
public void setCustomMsg(String customMsg)
{
this.customMsg = customMsg;
}
public GenericException(String customMsg)
{
this.customMsg = customMsg;
}
@Override
public String getMessage()
{
return message;
}
}
myController.java
@Controller
@RequestMapping(value = "/admin/store")
public class AdminController
{
//bunch of restful drivin requestMappings
}
問題: 我如何獲得任何及所有內部服務器錯誤&異常顯示異常/錯誤信息單頁?
您是否檢查過[this](http://forum.springsource.org/archive/index.php/t-77927.html)? –