tomcat-users mailing list archives

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

Howdy,
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
rd.include("/timeout.html").

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 [mailto:jan@diekleinedomain.de]
>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
load
>and
>pass a string specifying the calling pagename. The servlet then gets my
>user-object out of the request-session and checks whether the
particular
>user
>is allowed to access or not. If he is, the servlet just writes a
comment in
>to
>the stream and thats it. If however the user is not allowed to access
that
>particular resource, I want to redirect the user to a different page
within
>my
>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
only
>so
>far) and I am not sure how to go about forwarding from within my
servlet. I
>have tried the following:
>
>[snip]
>            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()
><BR>"+e);
>                out.close();
>            }
>[/snip]
>
>getPathToRoot() basically takes the request.getHeader("referer") and
>extracts
>the number of "/", minus those used in the hostname and returns a
string
>containing "../" for each "/" found and TIMEOUT_URL contains the
complete
>path
>to the resource from document-root.
>The url build out of those is correct in itself, the RequestDispatcher
>however
>doesn't forward to the right page but instead ignores all but the
pagename.
>
>It be very thankfull for any help & comment
>
>Jan
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message