struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Mitchell" <>
Subject Re: Subclassing ActionForward
Date Wed, 18 May 2005 17:24:11 GMT
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:

  <forward name="STATE__SESSION_EXPIRED" path="/sesson-expired.jsp"/>
...(removed for brevity)...

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 (, or nested either by configuration 
or using Modules (, all cases are 

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)

 - /
     (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.
AIM:   jmitchtx
Yahoo: jmitchtx

----- Original Message ----- 
From: "Lee Harrington" <>
To: "Struts Users Mailing List" <>
Sent: Wednesday, May 18, 2005 12:07 PM
Subject: Re: Subclassing ActionForward

Ok....have a 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 {



To unsubscribe, e-mail:
For additional commands, e-mail: 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message