I need to pass a variable from Admin.java file to index.jsp. I get the value when I print it in Admin.java. I need to pass that value to another variable which needs to be sent to index.jsp. This new variable gets null value.
The code in Admin.java is
public string static rest;
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
SemanticSearch semsearch = new SemanticSearch(request.getSession());
semsearch.loadData(REALPATH + RDFDATASOURCEFILE1);
String res=semsearch.searchForUser(userName, password);
System.out.println("The value of res been passed is "+res);
request.setAttribute("rest", res);
System.out.println("The value of rest is "+rest);
request.getRequestDispatcher("index.jsp").forward(request, response);
if(res != null)
{
request.getSession().setAttribute("access", true);
System.out.println("Admin:doGet:login:true");
response.getWriter().write("existsnoadmin");
return;
}
Output:
The value of res been passed is C Language.
The value of rest is null.
As per the questions asked in stack overflow we need to use forward or redirect when we need to send the value to jsp page. But in my case, I am trying to return value from a function so I do not know whether the way I am trying to do in the above code is right or not.
The code in index.jsp is:
if(response=="existsnoadmin")
{
alert(response);
alert("The value obtained by the admin.java is " +request.getAttribute("rest"));
out.println("The value obtained by the admin.java is " +request.getAttribute("rest"));
alert("we have done in index.jsp");
}
The output is that I am getting the alert box which says "existsnoadmin".
But I am not able to get the value of rest here nor in Admin.java.
What is the mistake I have done here? Please help.
Regards,
Archana.