wood burning stoves 2.0*
The moose likes Struts and the fly likes [Struts] forward actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "[Struts] forward actions" Watch "[Struts] forward actions" New topic
Author

[Struts] forward actions

J.H.B. Oosterlaar
Ranch Hand

Joined: Sep 12, 2002
Posts: 41
Hi,
I have a mixed page calls situation. Pages that need to display data from the database, are called by an Action that first loads the data from the database, puts it in a bean and forwards to the page, having the bean stored in the request scope. The page is called by showDataPage.do for example. Other pages that don't need to show anything are called directly by their .jsp name (login.jsp for example). I don't like this situation, so now I want to write a forward action for every page. The login.jsp page will be forwarded by for example the showLoginPage.do action, that doesn't anything but forwarding to the page. Is this acceptable? What do you think of this way of page requesting?
Thanks and cheers,
Jeroen Oosterlaar
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi Jeroen,
I think using Action class just to forward to jsp is okay. At least you can hide the path of that jsp file.
But probably using
org.apache.struts.actions.ForwardAction
would be a better solution. By using this, you don't have to create an Action class. You can specify that behavior in struts-config.xml alone.

<action path="/saveSubscription" type="org.apache.struts.actions.ForwardAction" name="subscriptionForm" scope="request" input="/subscription.jsp" parameter="/path/to/processing/servlet">
Just like this.
[ January 12, 2003: Message edited by: Shin Hashitani ]

/*<br /> * Quants Inc.<br /> * Engineer<br /> *<br /> * Shin Hashitani<br /> * hashitani@quants.co.jp<br /> * <a href="http://www.quants.co.jp" target="_blank" rel="nofollow">www.quants.co.jp</a><br />*/
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

Jeroen,
The approach is a good one -- for Struts applications, you always want to be going through a .do and never directly to a .jsp. This allows you to change the flow in the struts-config without affecting any of the jsps.
To define a simple forward mapping, you can do this:
<action path="/login" forward="login.jsp" />


Junilu - [How to Ask Questions] [How to Answer Questions]
J.H.B. Oosterlaar
Ranch Hand

Joined: Sep 12, 2002
Posts: 41
Thanks for your replies. I totally agree with your statements. That is why I wanted to do it that way in the first place, but I thought that maybe it was a bit uncommon.
Another question: is there then a way to prevent direct url access? Or that only the action forwards can be accessed, not the jsp pages, that they are forwarding to?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

Put your jsps in a non-public directory, such as under WEB-INF. Only the struts servlet will have access to them.
J.H.B. Oosterlaar
Ranch Hand

Joined: Sep 12, 2002
Posts: 41
You are right, that is it . But is that a good way of doing that? Or is it a bit easy-over-the-top? That may sound a bit silly, but I want to develop this webapplication, following the standard and ways things should be done.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

If it's good enough for Ted Husted, it's good enough for me See http://husted.com/struts/catalog.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Struts] forward actions