Hi Everybody,
I am facing a problem while trying to retrieve object from request scope.
I have added a object in the request scope through a servlet and than using RequestDispacther i have forwarded the request to the jsp and while trying to retrive the object in the jsp i am getting null.
Please find the code below,
Servlet Code :
package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.example.web.Person;
public class UseBeanTestServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
String personName = request.getParameter("personName");
Person personObj = new Person();
personObj.setName(personName);
request.setAttribute("PesronObj",personObj);
RequestDispatcher view = getServletContext().getRequestDispatcher("/UseBean.jsp");
view.forward(request,response);
}
}
Jsp Page :
<%@ page import="com.example.web.*"%>
<HTML>
<TITLE>
USE BEAN EXAMPLE
</TITLE>
<BODY>
Name : <%= ((String)request.getAttribute("personName"))%>
</BODY>
</HTML>
I have also tried adding object to servletContext, however after forwarding the request , for some reason i am not able to retrive the obj in the jsp.
Would appreciate all your help.
Regards,
Harsh
I am facing a problem while trying to retrieve object from request scope.
I have added a object in the request scope through a servlet and than using RequestDispacther i have forwarded the request to the jsp and while trying to retrive the object in the jsp i am getting null.
Please find the code below,
Servlet Code :
package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.example.web.Person;
public class UseBeanTestServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
String personName = request.getParameter("personName");
Person personObj = new Person();
personObj.setName(personName);
request.setAttribute("PesronObj",personObj);
RequestDispatcher view = getServletContext().getRequestDispatcher("/UseBean.jsp");
view.forward(request,response);
}
}
Jsp Page :
<%@ page import="com.example.web.*"%>
<HTML>
<TITLE>
USE BEAN EXAMPLE
</TITLE>
<BODY>
Name : <%= ((String)request.getAttribute("personName"))%>
</BODY>
</HTML>
I have also tried adding object to servletContext, however after forwarding the request , for some reason i am not able to retrive the obj in the jsp.
Would appreciate all your help.
Regards,
Harsh