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
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 ]
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" />
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?
Put your jsps in a non-public directory, such as under WEB-INF. Only the struts servlet will have access to them.
Joined: Sep 12, 2002
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.