我不知道我可能为引起这一点所做的配置更改,但是由于某种原因,到达无效的URL,该URL映射到没有struts2操作,只给出了一个空白页。它不会重定向到映射的404页,甚至没有显示"没有绘制的命名空间的动作[/]和动作名称[] []。我正在尝试使我的404页面正常工作,但是我不知道这里发生了什么。在我的web.xml中,我有:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<error-page>
<error-code>404</error-code>
<location>/jsp/error/404.jsp</location>
</error-page>
对为什么要使用无效的URL和动作的空白页面有任何想法?我感谢帮助
最后 - 在深入搜索此问题之后,我将找到一个很好的解决方案,可以使其如何工作!
1st:您需要添加 com.opensymphony.xwork2.unknownhandler bean bean bean中的 struts.xml :
<bean type="com.opensymphony.xwork2.UnknownHandler" name="handler" class="com.path.to.your.InvalidRequests"/>
第二:设置一个动作,参考未找到行为的页面。
<action name="pageNotFound" class="com.path.to.your.PageNotFound" method="execute">
<result name="success">/jsps/404.jsp</result>
</action>
3rd:在您的自定义处理程序中,您需要定义 com.opensymphony.xwork2.config.entities.entities.ActionConfig 并检查操作是否已经存在于您的操作配置列表中<</p>
public class InvalidRequests implements UnknownHandler {
@Override
public ActionConfig handleUnknownAction(String namespace, String actionName) throws XWorkException {
ConfigurationManager configurationManager = Dispatcher.getInstance().getConfigurationManager();
RuntimeConfiguration runtimeConfiguration = configurationManager.getConfiguration().getRuntimeConfiguration();
ActionConfig actionConfig = runtimeConfiguration.getActionConfig(namespace, actionName);
if(actionConfig == null) { // invalid url request, and this need to be handled
actionConfig = runtimeConfiguration.getActionConfig("", "pageNotFound");
}
return actionConfig;
}
// ... also you need to implements handleUnknownResult, handleUnknownActionMethod
}
请记住,您需要覆盖这两种方法 handleunknownResult 和 handle unkNownActionMethod ,并且这两种方法都返回 null 。