码迷,mamicode.com
首页 > Web开发 > 详细

struts2整合json要注意的问题

时间:2014-06-27 07:44:37      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:struts2   json   

昨天struts2整合json,一直出错:

There is no Action mapped for namespace / and action name ...

HTTP Status 404 - There is no Action mapped for action name...

发现我已经在struts.xml中继承了json-default了啊,后来发现原来是因为没有引入相应的包,在此做下总结。


1、添加相应的包


导入commons-beanutils-1.7.0.jar、ezmorph-1.0.3.jar、json-lib-2.1-jdk15.jar、struts2-json-plugin-2.2.3.jar四个包,这些包在Struts的lib目录下都可以找到。


2、要继承json-default

<package name="struts2" extends="json-default" namespace="/">


json-default其实也是最终继承struts-default的 json-plugn中struts-plugn.xml源码如下

<struts>
    <package name="json-default" extends="struts-default">
        <result-types>
            <result-type name="json" class="org.apache.struts2.json.JSONResult"/>
        </result-types>
        <interceptors>
            <interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
        </interceptors>
    </package>
</struts>


这里你可以看到这个json-default是干了什么事情,无非就是:

  • 加了个名为json的result类型
  • 加了一层名为json的拦截器


配置完后,就可以使用Struts+json啦!

struts2整合json要注意的问题,布布扣,bubuko.com

struts2整合json要注意的问题

标签:struts2   json   

原文地址:http://blog.csdn.net/bruce_6/article/details/34826071

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!