Struts 2当用户插入不存在的操作时该做什么 [英] Struts 2 what to do when user inserts action which does not exist

查看:129
本文介绍了Struts 2当用户插入不存在的操作时该做什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Struts 2应用程序中,当用户插入与您的任何操作无关的URL时, java.lang.NullPointerException

In a Struts 2 application when user inserts an URL which is not related with any of your actions a java.lang.NullPointerException arises

在这些情况下,我想显示一个漂亮的屏幕,所以我添加了我的 struts.xml

in these cases I want to display a nice screen so I have added in my struts.xml

<global-exception-mappings>
    <exception-mapping exception="java.lang.NullPointerException" result="exception"/>
</global-exception-mappings>

<global-results>
    <result name="exception">/WEB-INF/jsp/exception.jsp</result>
</global-results>

但它不起作用。我也试过没有成功

but it doesn't work. I also have tried without success

<action name="exception">
    <result>/WEB-INF/jsp/exception.jsp</result>
</action>

所以,我开始认为所有的URL都必须与一个动作相对应,否则有没有任何机制来处理这些情况,当用户插入不符合任何动作的URL(因此这个机制是处理由您现有的一个操作导致的$ code> NullpointerException 这不存在)。

so, I'm starting to think that all URLs have to correspond with an action, otherwise there is no mechanism to handle these cases when users insert URLs which don't correspond to any action (so this mechanism is to handle NullpointerExceptions caused by one of your existing actions, not one that doesn't exist).

推荐答案

你去:

 <default-action-ref name="index"/>

如果没有找到匹配项,此操作将被调用。

This action will be called if no match is found.

我在我的所有应用程序中使用它,以避免日志中出现不必要的错误/警告。

I use this in all my apps to avoid unwanted errors/warnings in the logs.

文档

这篇关于Struts 2当用户插入不存在的操作时该做什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆