Struts2 访问出错 :http 500

Struts2 访问出错 :http 500

错误信息:

 

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
        org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
        com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
        org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
 org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
 com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
        org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:501)
        org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:432)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.37 logs.


Apache Tomcat/7.0.37

 

 

错误原因:

 1.     原因:struts2 的默认配置中,struts2会拦截所有的请求,包括各种后缀,因此,当访问一个不存在的目录时(即没有明确给出一个文件及其后缀名),struts2 会将其匹配为一个命名空间,然后在struts.xml 中查找对应的 action。如果你的struts2 的处理后缀没有改动,那么如果该命名空间(也即前面访问的目录)中正好没有配置默认的action,则出现 http 500的错误,而不是 404 错误,因为struts2 工厂找不到 action去构造,出现空指针异常。

解决方法:

1.     方法一:

Strut2 的配置文件 struts.xml 中,加入:

<constant  name="struts.action.extension" value="action,do"></constant>

即将struts2 的处理后缀改为 actiondo (当然可以改为其他)。这样的话,当访问一个不存在的路径(目录)时,struts2 将不会认为其是一个命名空间,也不会去寻找这个命名空间中的默认 action,那么就不会出现该问题。

问题解决。

2.     方法二:

struts2的配置文件struts.xml中的默认包下,配置一个默认action

 

      <!-- 默认action -->

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

      <action name="index">

      <result>/index.jsp</result>

</action>

 

即可。如上,这个 action 其类型为默认的 ActionSupport,跳转到应用首页。

转载于:https://www.cnblogs.com/ilvu/archive/2013/04/30/3051879.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值