Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on request.getAttribute() returns null in jsp within the JSP forums, part of the Web Development category; Hi Friends, 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 ...
|
|||||||
|
|||
|
request.getAttribute() returns null in jsp
Hi Friends,
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. Plz help me to do this.......... Thanks in advance............ |
| Sponsored Links |
|
|||
|
Re: request.getAttribute() returns null in jsp
Hi, in the request, you are setting the attribute "personobj" and in jsp you are trying to get the attribute "personName" . kindly check that.
Quote:
|
| The Following User Says Thank You to ShruthiL For This Useful Post: | ||
|
|||
|
Re: request.getAttribute() returns null in jsp
Hi,
Yes, U r right. The issue is already solved... Anyways Thanks for u r effort... The corrected jsp code... <%@ page import="com.example.web.*"%> <HTML> <TITLE> USE BEAN EXAMPLE </TITLE> <BODY> Name : <%= ((Person)request.getAttribute("PesronObj"))%> </BODY> </HTML> Thanks, Riju. |
|
|||
|
Re: request.getAttribute() returns null in jsp
Hi, Try the below. It will work.
your first jsp. (UseBeanTest.jsp) Quote:
Quote:
UseBean.jsp Quote:
Hope it helps. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What does printf function returns? | chaitanyawithu | C and C++ | 6 | 05-20-2008 02:03 PM |
| I have 4 million row but mapping returns only 400000 rows | palakpari | Data Warehousing | 1 | 07-03-2007 02:09 AM |
| Built-in and plugin stages, Chaning Null to Not Null and Types of lookup | Geek_Guest | Data Warehousing | 0 | 04-06-2007 04:48 AM |
| Query that returns all responsibilities of a function | JobHelper | Oracle | 0 | 01-04-2007 09:46 AM |
| Web Service method returns a vector of objects | ssumitha | ASP.NET | 1 | 12-14-2006 08:25 AM |