1 在action内直接抛出对应的exception
<span style="font-size:24px;">public String execute() throws Exception
{
if(getInput().equals("exception"))
{
throw new Exception("谁让你输入exception的!");
}</span>
2 在Struts.xml配置对应的结果 可以配置全局的异常处理结果 ,也可以配置局部的
(1)全局配置
<span style="font-size:24px;"><global-results>
<result name="global-exception">/WEB-INF/exception.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="global-exception" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings></span>
(2)局部配置
<span style="font-size:24px;"><!-- servletApi -->
<action name="servletApi" class="com.songxu.action.ServletAPIAction">
<exception-mapping result="exception" exception="java.lang.Exception"></exception-mapping>
<result name="success">/ActionToServletAPI/Result.jsp</result>
<result name="exception">/WEB-INF/exception.jsp</result>
</action></span>