wood burning stoves 2.0*
The moose likes Struts and the fly likes How to do Action mapping for this scenario ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to do Action mapping for this scenario ??" Watch "How to do Action mapping for this scenario ??" New topic
Author

How to do Action mapping for this scenario ??

steve francisco
Ranch Hand

Joined: Jan 26, 2005
Posts: 46
Prior to learning struts, I wrote a servlet/jsp/action application and it works like this ---

In my central servlet "ControlServlet", it takes "action" as a parameter and the servlet code includes ---

****
if(action.equsls("act1")) { initiate and call Action1 class; forward to jsp1; }
if(action.equals("act2")) { initiate and call Action2 class; forward to jsp2; }
....
****

In jsp1 and jsp2, both of them include html FORM. when "submit" is clicked, it calls "ControlServlet" again, they also carry the "action" parameter as a hidden variable so that "ControlServlet" knows what's the next page it should dispatch to. SO, the overall flow is like

Browser --> /ControlServlet?action=act1 , then it calls "Action1" class and directs to jsp1; in jsp1 after "submit" is clicked --> /ControlServlet?action=act2, then it calls "Action2" class and directs to jsp2...

How to change it into a struts ? the biggest issue is "how to do the action and action mapping " ? Please help me check if the following makes sense ---

<action-mapping>
<action path="/ControlServlet?action=act1"
type="Action1"
(I do NOT put "name=" here because in the First time the servlet gets no input bean !)
input="/ControlServlet?action=act1"
scope="request">
<forward name="ok" path="/jsp1" /></action>

<action path="/ControlServlet?action=act2"
type="Action2"
name="jsp1BeanForm" (this is the content of jsp1 input page)
input="jsp1"
scope="request"
<forward name="ok" path="/jsp2" /></action>

</action-mapping>
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
ok, first of all, struts itself is a single controller servlet. what you are looking to do is to define 2 separate Action classes (a.k.a request processor) you can use also DispatchedAction or MappedDispatchedAction to combine into 1 class), each with its own action-mapping and forward. they are essentially identical. The first action-mapping calls
<p />

<action path="action1" type="com.xxx.Action1">
<forward name="showJsp1" path="jsp1.jsp"/>
</action>

<action path="action2" type="com.xxx.Action2">
<forward name="showJsp1" path="jsp1.jsp"/>
</action>


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
stupid form!!! i hit submit by mistake while copy and paste...the second action should be:
<br />
<action path="action2" type="com.xxx.Action2">
<forward name="showJsp2" path="jsp2.jsp"/>
</action>

the meat of what you are doing now in your controller should be done inside the execute() of each action. upon success, you must set your forward value to "showJsp1" or "showJsp2".

you can also use 1 action and pass parameter in (in the form of the first jsp). then user request.getParameter() to do conditional statement. what you are asking is very basic of struts.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to do Action mapping for this scenario ??