Hi,
I want to pass int and string array form an servlet to jsp. I retrieve the data from form database code and store it in the strings. The string arrays are not empty ( I checked it by directly running servlet in browser and printing the values by using PrintWriter ).
I'm using session.setAttribute() in servlet and session.getAttribute() in jsp below is the code ,
servlet code
/*
DataBase code
*/
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String ge=req.getParameter("CMD");
HttpSession session=req.getSession(true);
if (ge.equals("geQ"))
{
/* int c2=0;
while (c2<5)
{
out.println(Q[c2]+"<br>");
c2++;
} */
}
session.setAttribute("Q",Q); // Q is string
}
Jsp code
<%@ page session="true"%>
<body onload=http://localhost:8080/OLT/GeQuest?CMD=geQ> // to call the servlet when page loads to generate DataBase Query
<%!String[] srt=(String)session.getAttribute("Q");
%>
<%while(i<5)
{%>
<%=srt%>
<%
i++;
}%>
</body>
But I'm getting Error : session cannot be resolved
I'm not sure that this is a proper way to do it. Please help me out if you have any suggestions for this problem.
Thanks in advance,
Harsh