• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

[Struts] forward actions

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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" />
 
J.H.B. Oosterlaar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's good enough for Ted Husted, it's good enough for me See http://husted.com/struts/catalog.html
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic