struts2的应用

来源:互联网 发布:程序员培训课程付费 编辑:程序博客网 时间:2024/06/08 03:43
1.通过struts2框架从后台传输到前台的对象(opeSearchDTO),有两种方式显示其值:

(1)jsp页面上使用的是普通的jsp标签(如input,button等等):
<input type="hidden" id="idText" value="<s:property value="opeSearchDTO.id"/>"/>

(2)jsp页面上使用的是struts2提供的s标签(如s:textfield,s:form等等):
<s:label id="opeIdText" name="opeSearchDTO.opeId" ></s:label><s:textfield id="opeName1Text" name="opeSearchDTO.opeName1" />


2.struts2会自动封装后台的对象到json对象中供前台读取,但是这不包括父类的属性,要想将父类的属性一起封装,需要修改struts.xml文件,在action标签中配置<param name="ignoreHierarchy">false</param>
<action name="opegrpdetail" class="opeGrpDetailAction"><result type="json"><param name="ignoreHierarchy">false</param></result></action>

并且要注意,父类的该属性的set和get必须是public的,protect是不会被封装的。

3.struts2无法将service序列化为json对象,一般action中注入的service要排除在struts2的序列化对象之外,否则struts2的序列化会出错。有两种办法:
(1)只为该service对象提供set方法,不要提供get方法(struts2会将所有为其提供了public类型getter的属性全部作为序列化对象)。
(2)如果非要提供service的get方法,可以在getter前加上这段命令将其排除在序列化对象之外:
@JSON(deserialize = false, serialize = false)public OperatorService getOperatorService() {return operatorService;}


4.为了防止工程在服务器上发布后出现找不到url的路径,可以将ajax的option中的url不要写死在js中,而是将action的url写在jsp的一个hidden域中,然后js去读取这个值,如下:
<input type="hidden" id="operegist_action"        value="<s:url namespace="/opemgr_ajax" action="operegist"/>"> 
0 0