• Struts2与Json


    首先,要添加ezmorph-1.0.3.jar和morph-1.1.1.jar这两个jar。

    然后在struts.xml里面,添加json-default

    <package name="default" extends="struts-default,json-default">
    <action name="TypeAction_*" class="TypeAction" method="{1}">
        <result name ="VIEW_SUCCESS" >LoadPage/type.jsp</result>
        <result name ="ADD_SUCCESS" >CommonPage/ajaxDoneType.html</result>
        <result name ="ADD_FAILED" >CommonPage/ajaxDoneFailed.html</result>
        <result name ="DELETE_SUCCESS" >CommonPage/ajaxDoneType.html</result>
        <result name = "UPDATEPRO_SUCCESS" >DealPage/typeUpdate.jsp</result>
        <result name = "UPDATE_SUCCESS" >CommonPage/ajaxDoneType.html</result>
    </action>
    <action name="BuildingAction_*" class="BuildingAction" method="{1}">
        <result name ="VIEW_SUCCESS" >LoadPage/building.jsp</result>
        <result name ="ADD_SUCCESS" >CommonPage/ajaxDoneBuilding.html</result>
        <result name ="ADD_FAILED" >CommonPage/ajaxDoneFailed.html</result>
        <result name ="DELETE_SUCCESS" >CommonPage/ajaxDoneBuilding.html</result>
        <result name = "UPDATEPRO_SUCCESS" >DealPage/buildingUpdate.jsp</result>
        <result name = "UPDATE_SUCCESS" >CommonPage/ajaxDoneBuilding.html</result>
        <result name = "ALLSELECT_SUCCESS" >DealPage/buildingAdd.jsp</result>
        <result name = "SEARCHPRO_SUCCESS" >SearchBuildingPage/buildingSearch2.jsp</result>
        <result name = "DETAILSELECT_SUCCESS" type = "json">
          <param name="root">detailresults</param>
          <param name="contentType">application/json</param>
        </result>
        <result name = "SEARCH_SUCCESS" type = "json">
          <param name="includeProperties">buildingresults.*,pagerresult.*</param>
          <param name="contentType">application/json</param>
        </result>
        <result name = "SEARCH2_SUCCESS" >/SearchBuildingPage/building.jsp</result>
        <result name = "SEARCH3_SUCCESS" >SearchBuildingPage/buildingSearch2.jsp</result>
    </action>
    </package>

    当然,也可以把struts-default和json-default分开写,我是因为,方便查看,所以写到一起了。

        另外,上面的action用的了匹配。如TypeAction_*:TypeAction是action类的名称,* 是此类里的方法名称,* 的数量也可以,进一步添加的,匹配的东西也就相应增多。

    includeProperties与root的不同是,对于数据,root是从根节点开始。includeProperties是从根包含的元素开始,相当于去除了根。

  • 相关阅读:
    POJ 1741
    POJ 3107
    权限管理
    用户和组
    软件包管理简介
    制作网线
    认识vim编辑器
    linux 进阶命令
    linux 目录&基础命令
    在raw_input()中使用中文提示,在CMD下中文乱码问题解决。。。
  • 原文地址:https://www.cnblogs.com/idealing/p/3134778.html
Copyright © 2020-2023  润新知