Difficulty using session object in JSP
I am trying to pass a value from one jsp page to another.
For simplicity in my example the pages are pg1.jsp and pg2.jsp
In pg1.jsp I do as follows.
HttpSessionContext sc=request.getSession().getSessionContext();
request.setAttribute("name", "clive");
String pg2 ="pg2.jsp";
RequestDispatcher pg2Dispatcher = request.getRequestDispatcher(pg2);
try {
pg2Dispatcher .include(request, response);
} catch (Exception exception) {
out.println("Error: " + exception);
}
on pg2.jsp
<%
String country = request.getParameter("country");
%>
<b> <%=country%>
<%
This displays "null" on the generated html
If I try to use session instead.
On pg1.jsp
try {
session.include(request, response);
} catch (Exception exception) {
out.println("Error: " + exception);
}
An error occurred at line: 26 in the jsp file:pg2.jsp
session cannot be resolved
23:
24: if (desktopDispatcher != null){ */
25: try {
26: session.include(request, response);
27: } catch (Exception exception) {
28: out.println("Error: " + exception);
29: }
I thought that session was automatically available in jsp.
My question is, how can I use Session session, or HTTPSession sesssion inside CQ to pass a variable from one jsp to another?
Regards
Clive Stewart