Struts 中的向导表单
我正在 Struts 中创建一个向导。 它包含 4 个步骤。 对于每个步骤,我都有单独的 ActionClass 说:-
- Step1Action.java
- Step2Action.java
- Step3Action.java
- Step4Action.java
在每个类中有 2 个方法 input() 和 process()。
- input() 方法用于以输入模式显示页面
- process() 方法将用于处理提交的数据(如果验证正常)
我携带所有数据直到会话的最后一步。并在最后一步中将它们全部保存在数据库中,
类似 struts.xml 中的 4 个操作标记,例如:-
<action name="step1" class="com.mycomp.myapp.action.Step1Action1" method="input">
<result name="success" type="redirectAction">step2</result>
<result name="input">/view/step1.jsp</result>
</action>
<action name="step2" class="com.mycomp.myapp.action.Step1Action2" method="input">
<result name="success" type="redirectAction">step3</result>
<result name="input">/view/step2.jsp</result>
</action>
但我认为我错了。请告诉我我将如何处理此案?
I am creating a wizard in Struts.
It cotains 4 steps.
For Each step I have separate ActionClass say:-
- Step1Action.java
- Step2Action.java
- Step3Action.java
- Step4Action.java
and in each class there are 2 methods input() and process().
- input() method is for showing the page in input mode
- process() method is will be use for processing the submitted data (if validation is ok)
I am carrying all data upto the last step in a session. And saving all of them in database in the last step
Similaly 4 action tags in struts.xml like :-
<action name="step1" class="com.mycomp.myapp.action.Step1Action1" method="input">
<result name="success" type="redirectAction">step2</result>
<result name="input">/view/step1.jsp</result>
</action>
<action name="step2" class="com.mycomp.myapp.action.Step1Action2" method="input">
<result name="success" type="redirectAction">step3</result>
<result name="input">/view/step2.jsp</result>
</action>
But I think I am going wrong. Please Tell me How will I handle This case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在尝试开发一些类似向导的功能,那么 struts2 中已经有一个用于相同作用域拦截器的拦截器
这是相同的详细信息
http://struts.apache.org/2.0.14/docs/scope -拦截器.html
If you are trying to develop some wizard like functionality than there is already an interceptor in struts2 for the same Scope Interceptor
here are the details for the same
http://struts.apache.org/2.0.14/docs/scope-interceptor.html
这里有一些概念上的错误 - 并且概念上的错误位于向导场景之前。
一方面,Struts2 操作(通常)不应该有“输入”方法。 Struts2 操作应该代表客户端请求(URL)执行某些操作(方法),并返回 RESULT(字符串),该结果将新的 VIEW(jsp 页面)返回给客户端。
“输入”(通常)只是一个与情况相对应的结果“我无法执行我(操作)应该执行的操作,因为输入的数据不完整或无效;让我们告诉用户尝试输入 在尝试使用向导之前,
您应该确保了解最简单的用例(带有结果消息的典型输入表单)。请参阅此处。
There is something conceptually wrong here - and the conceptual error lies before the wizard scenario.
For one thing, a Struts2 action should not (typically) have a "input" method. A Struts2 action should DO SOMETHING (method) on behalf of a client request (URL), and return a RESULT (string) which returns a new VIEW (jsp page) to the client.
"input" is (conventionally) just a RESULT that corresponds to the case "I cannot do what I (action) am supposed to do because the data entered is incomplete, or invalid; let's tell the user to try to input the data again"
You should be sure to understand the simplest use cases (the typical input form with a result message), before attempting a wizard. See here.