Scope of URL Query String Parameters to JSPs That Are Included By Other Pages
Posted on 2004-10-13
I have a small JSP TV-Listings code snippet ('mini_listings4.jsp') that is always designed to be used by a parent page that includes it. The JSP include pulls out tv listings for a particular day (don't worry I've got this bit working perfectly) and Xpaths them for display. It is important to realise that the parent page that includes this TV listings JSP, doesn't necessarily have to be a JSP itself; it could be an '.htm' file using a <!--#include virtual="mini_listings4.jsp" ---> to pull in the TV listings JSP.
Here's my problem. I'm using code in the TV-Listings JSP include to sniff out a query string that may or may not be appended after the parent's page URL to determine whether it is today's or tomorrow's TV schedule that is displayed. If it's today's TV (default) to be displayed, then a link is output for dispaying tomorrow's TV ('<a href="?showtvfor=tomorrow">' and vice versa if the parameter stipulates that it's tomorrow's TV to display. The problem is that the JSP included cannot see the query string because it considers it be solely within the scope of the parent page that pulls it in. So these lines in the JSP include:
out.println("<!-- " + request.getQueryString(); + "-->");
out.println("<!-- " + request.getParameter("showtvfor") + "-->");
result in "<!-- -->" and "<!-- null-->" when the JSP is invoked as an include (even if the URL of the parent page that pulls it in is "www.mydomain.com/T/test/full4ltvlistsings.htm?showtvfor=tomorrow"
But if you pointed your browser to the JSP directly, it works fine (see below):
Anybody got a fix or should I create a JSP session variable instead?