请告诉我准备者的工作原理
我现在正在使用它并发现了strage行为
prepare()
validate()
execute()
这些是方法
所以当我点击请求时,它调用了3次
prepare()
validate()
execute()
prepare()
validate()
execute()
prepare()
validate()
execute()
我不知道这是什么问题
根据我的理解,它应该只运行准备方法并显示预先填充的数据表格,当用户单击提交时,它应该提交数据。
请解释
<action name="updatebusinessinfo" class="com.controller.UpdateBusinessDetails">
<interceptor-ref name="params"/>
<!--
<interceptor-ref name="prepare"/>
<interceptor-ref name="basicStack"/>
-->
<interceptor-ref name="fileUpload">
<param name="maximumSize">2097152</param>
<param name="allowedTypes">image/png,image/gif,image/jpeg,image/pjpeg</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success">businessinfo.jsp</result>
<result name="input">businessinfo.jsp</result>
<result name="error">businessinfo.jsp</result>
</action>
是的朋友,我在struts.xml文件中犯了错误。
现在,请告诉我如何在
prepare()
方法中接收url参数?http://www.myweb.com/updatebusinessinfo/23
我尝试跟随但无法正常工作
<action name="updatebusinessinfo/*" class="com.controller.UpdateBusinessDetails">
<param name="id">{1}</param>
<interceptor-ref name="params"/>
<!--
<interceptor-ref name="prepare"/>
<interceptor-ref name="basicStack"/>
-->
<interceptor-ref name="fileUpload">
<param name="maximumSize">2097152</param>
<param name="allowedTypes">image/png,image/gif,image/jpeg,image/pjpeg</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success">businessinfo.jsp</result>
<result name="input">businessinfo.jsp</result>
<result name="error">businessinfo.jsp</result>
</action>
最佳答案
有关此问题的一些提示可能会在寻找有关“准备拦截器”信息的人们中派上用场:
struts2中的DefaultStack已经包含了Prepare拦截器,因此,如果将它们都包含在内,则将有两个调用prepare()。通常,您不想要那样。
在DefaultStack中,Prepare拦截器在Params拦截器之前被称为,因此prepare()方法中不会包含请求参数。如果您想在其中使用参数进行操作(例如,从具有ID的DB中获取某些内容),则将无法执行。
查看此处以了解struts2中的基本/默认堆栈:
http://struts.apache.org/release/2.0.x/docs/struts-defaultxml.html
有一个“ paramsPrepareParamsStack”,它在Prepare之前和之后使用Params,因此您可以在prepare()中使用params。