The recommendation is simply to have Actions handle all of your app's
requests, rather than sending users to "bare" (no Action in front) JSPs.
That means that the user's browser should never have a URL that ends in
.jsp. Some of your Actions may be pretty thin in that all they do is forward
to the JSP that backs them, but making sure to send them through an Action
first has a few advantages. One is that many apps require some processing
that you can't do without going through an Action first. It could be simply
having Struts check that the user has a required role, or there might be
some application-specific processing in a RequestProcessor or an ActionBase
class that is specific to your app. Another advanatge is that if you later
decide that you need to do some processing in the controller for a
particular request, you don't have to change the URL of that request
(requiring changes to pages that link to that request, and breaking any
bookmarks users may have for it). You can just add the new processing to the
existing Action, or even create a new Action and change the mapping to use
the new Action (which still doesn't change the URL).

Using forwards with redirect="true" is fine, as long as you aren't
redirecting them directly to a jsp. <forward path="/someOtherAction.do"
redirect="true"/> does not violate the recommendation. In fact, I think it
is a good practice to use redirects in some instances, so that the url in
the browser's address bar matches the content the user is seeing (it also
solves some resubmit-on-back-button issues). I often use a POST followed by
a redirect for forms that change the contents of the db -- like when someone
submits a change to an 'item' on an 'edit item' page and then you send them
back to a 'list of items' page. Since they end up at the 'list of items'
page, using a redirect allows you to process the 'edit item' submit and then
redirect them back to the 'list of items' URL.

-Max

----- Original Message ----- 
From: "Simon Matic Langford" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, October 25, 2003 2:08 AM
Subject: going straight to a jsp


> Hi,
>
> I've been using struts for a couple of months now, and have been
> working on the assumption that it is a bad thing to allow users
> to go directly to jsp's. So I have ensured that I don't use
> redirect="true" on forwards from an Action.
>
> Is this considered best practice for Struts? And are there any concrete
> reasons for or against this practice?
>
> Thanks
>
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to