tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <>
Subject RE: Forwarding from within a Servlet
Date Tue, 29 Apr 2003 14:32:31 GMT

The request dispatcher expects an argument starting with a /, not ../.
The argument is relative to the context root, aka the docBase of your
webapp.  So if your timeout.html page is at the docbase, call

Also consider using one of the following alternatives:
- RequestDispatcher.forward to a servlet that handles unauthorized users
and/or timeouts
- Throwing a specific exception, e.g. UnauthorizedUserException, which
you have mapped (via an <error-page> tag in web.xml) to a handler.  This
way you don't have to the redirection manually, as the container will do
it for you automatically.

Yoav Shapira
Millennium ChemInformatics

>-----Original Message-----
>From: Jan Behrens []
>Sent: Tuesday, April 29, 2003 9:34 AM
>To: Tomcat Users List
>Subject: Forwarding from within a Servlet
>Hi List,
>I have a servlet that is supposed to controll the access of app-users
on a
>"per keyword" base. Certain jsp's in my app include that servlet on
>pass a string specifying the calling pagename. The servlet then gets my
>user-object out of the request-session and checks whether the
>is allowed to access or not. If he is, the servlet just writes a
comment in
>the stream and thats it. If however the user is not allowed to access
>particular resource, I want to redirect the user to a different page
>app. If the session expired and therefore no user-object could be
found, I
>would like to forward the user to a different page...
>My problem is that I am quite new to servlets (have worked with jsp's
>far) and I am not sure how to go about forwarding from within my
servlet. I
>have tried the following:
>            if(DEBUG)out.println("<BR>logOutUser<BR>");
>            RequestDispatcher rd =
>request.getRequestDispatcher(getPathToRoot(request) + TIMEOUT_URL);
>            try {
>                rd.include(request,response);
>                out.close();
>            }catch (Exception e) {
>                if(DEBUG)out.println("accessControll.accessDenied()
>                out.close();
>            }
>getPathToRoot() basically takes the request.getHeader("referer") and
>the number of "/", minus those used in the hostname and returns a
>containing "../" for each "/" found and TIMEOUT_URL contains the
>to the resource from document-root.
>The url build out of those is correct in itself, the RequestDispatcher
>doesn't forward to the right page but instead ignores all but the
>It be very thankfull for any help & comment
>To unsubscribe, e-mail:
>For additional commands, e-mail:

This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.

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

View raw message