In plain old servlets
I can use doGet
and doPost
methods. Where in doGet
i'm forwarding user to some page and in doPost
i'm proccessing data entered from the page that I gave. That all happening in one servlet.
But the Struts2 works on Front Controller pattern and instead doGet/doPost
I have only execute
method. So how can I properly give user some page, so then he can see it, enter data, submit and application as result proccess it in execute
?
From what I know I have two options (example on registration form):
Map page to another url:
<action name="register_display"> <result name="success" type="dispatcher">register.jsp</result> </action> <action name="register" class="magazine.action.client.RegisterClientAction" method="execute"> <result name="success" type="redirectAction">/index</result> <result name="error" type="redirectAction">register_display </result> </action>
Create whole package named
display
and place there all view from which POST can be performed:<package name="display" namespace="/display" extends="struts-default"> <action name="register"> <result name="success" type="dispatcher">register.jsp</result> </action> ... </package>
Is there any other options ? Which one is prefered ?