You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jan Behrens <ja...@diekleinedomain.de> on 2003/04/29 15:34:26 UTC

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