I don't want users to be able to directly access a particular JSP by typing in the URL to it. I mean, if they do that, I want the JSP to immediately forward them to the servlet that will eventually forward them to that JSP. What can I put at the top of the JSP to check and see if a servlet just forwarded them to this JSP, and if not, then forward (?) them on to the servlet? When a servlet forwards to a JSP, is it basically a GET request, or slightly different since it's all on the server side?
Simply place the JSP somewhere in a folder structure under WEB-INF and there will be no way for it to be accessed directly via URL. I usually create a hierarchy rooted at WEB-INF/pages in which I place all my JSPs.
Placing them there does not prevent a servlet from forwarding to the page, but does prevent them from being directly accessed.
I agree wholeheartedly seeing as how that is much cleaner design, but right now I just need a quick short-term hack if one is available. I don't want to both with extra request parameters or bean variables if that's what would be necessary. Is it possible to check the request and see if the request was for the JSP or the servlet? (I mean, check the request URL or something like that).
Even though it doesn't necessarily sound that way from here, I guess forward(request, response) essentially calls a GET on the resource you're forwarding to (or something that overwrites the needed info in the request), because at the top of my JSP, request.getRequestURI says the JSP no matter whether I access the JSP directly or first call a GET on the servlet that forwards me to the JSP.
Rats. [ November 09, 2004: Message edited by: Stephen Huey ]
Joined: Jul 15, 2003
Aaaaaaaaaaaaaaaaaaaah...getRequestURL() does the trick! Not getRequestURI()