• 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啦!

  • 相关阅读:
    peudoclass与pseudo的相同点与不同点
    第一个页面
    自我介绍
    Virtual IP Address 学习记录
    OpenStack 学习记录
    Dubbo学习记录 MAC
    售前 银行
    log4j2 学习记录 Pattern Layout
    Zookeeper学习记录 mac下安装部署
    P2695 骑士的工作
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/3831219.html
Copyright © 2020-2023  润新知