I'm all for doing things "the struts way".
What I don't see in your example is WHERE to either throw the
exception or call the global forward. I'm trying to avoid putting
this in all my actions (btw, I use dispatch actions).
I did have the foresight to subclass the dispatchAction class:
public class BaseDispatchAction extends DispatchAction {
/**
*
*/
public BaseDispatchAction() {
super();
}
public static void main(String[] args) {
}
}
I just don't see where I have access to my "struts goodies" like
request, mapping etc.
Sorry to be so dull.
Lee
On 5/18/05, James Mitchell <[EMAIL PROTECTED]> wrote:
> I do not recommend using a filter. You are much better off using what
> you've already invested your time in (Struts).
>
> By using a base action as a single point of entry into your Actions, you can
> do this check in one place, and reuse any resources already handed to you in
> your base action.
>
> You could:
> a) forward to some global forward
>
> For example:
>
> <global-forwards>
> <forward name="STATE__SESSION_EXPIRED" path="/sesson-expired.jsp"/>
> ...(removed for brevity)...
> <global-forwards>
>
> b) throw an exception that you've globally configured
> Struts to handle (declarative exception handling)
>
> With b you now have a declarative way to handle an expired
> sessions and you have full access to your resource bundle.
>
> With either approach, you don't have to worry about whether your app is the
> root application (http://www.myapp.com/), or nested either by configuration
> or using Modules (http://www.myapp.com/go/here/for/my/app/), all cases are
> handled.
>
> With a filter, you would basically have to hard code where your app goes.
> For example:
> - /foo.jsp
> (single jsp to display some friendly error message)
>
> - /NonStruts/SessionExpiredCustomServlet
> (custom servlet for dealing with sessions)
>
> - /SessionExpired.do
> (forward to Struts anyway.....bad idea)
>
> Sure, you could get foo.jsp (from above) as a context-param, but I like to
> keep my work in one place, the struts-config.xml file.
>
> --
> James Mitchell
> Software Engineer / Open Source Evangelist
> Consulting / Mentoring / Freelance
> EdgeTech, Inc.
> http://www.edgetechservices.net/
> 678.910.8017
> AIM: jmitchtx
> Yahoo: jmitchtx
> MSN: [EMAIL PROTECTED]
>
>
> ----- Original Message -----
> From: "Lee Harrington" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[email protected]>
> Sent: Wednesday, May 18, 2005 12:07 PM
> Subject: Re: Subclassing ActionForward
>
> Ok....have a filter...it runs (use logging to determine this).
>
> I'm stuck on how to forward to the login page.
>
> Here's my filter code:
>
> public void doFilter(ServletRequest request,
> ServletResponse response,
> FilterChain chain)
> throws IOException, ServletException {
>
> try {
> chain.doFilter(request, response);
> //
> // Ensure there is a user in the session
> //
> UserDTO user = (UserDTO) request.getSession().getAttribute("user");
> if (user==null) {
> // User is not logged in, redirect to login page
> // How do I do that?
> }
>
> } finally {
> }
> }
>
> TIA,
>
> Lee
>
> ---------------------------------------------------------------------
> 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]