--------------第一种是胡乱敲,后缀不是以action结尾,出现404错误-----------------------------
解决方法:
web.xml中添加:
404.jsp
测试:
官方解释:
------------------第二种是胡乱敲,后缀是以action结尾,这样会被struts拦截--------------------------
由于是以.action结尾,会被struts拦截,可是找不到匹配的action映射,所以报错。
解决办法:
xml:
<package name="test2" extends="struts-default"> <default-action-ref name="notFound" /> <action name="notFound" class="cn.qlq.Action.TestAction2" method="notFound"> <result name="notFound">/404.jsp</result> </action> </package>
需要提醒的是
不要给上面的package指定namespace。另外,action的 result 一定要声明。除非在global-results中刚好有一个result 与你的“notFound()”这个方法所要跳转的result的名字 是一样的。
上面的配置的意思就是,在package下配置一个 default action,这个当输入的action找不到的时候,就会使用此action来进行处理。
以上面的配置来说,当一个action找不到时候,就会调用cn.qlq.Action.TestAction2的notFound方法来对应,然后跳转到404.jsp。这个方法的实现如下:
Action:
package cn.qlq.Action; import com.opensymphony.xwork2.ActionSupport; public class TestAction2 extends ActionSupport { public String notFound() { return "notFound"; } }
测试:
时间: 2024-08-28 03:29:01