Forums Register Login

problem with jsp:useBean

+Pie Number of slices to send: Send
I written a servlet, NewServlet with /NewServlet.do url-pattern for it.

In NewServlet I registered a Person object as follows

Person p = new Person();
p.setUsername("sai");
p.setPassword("xxx");
request.setAttribute("person",p);

then i forwarded the request to /index.jsp

Next, inside index.jsp i wrote this code

<jsp:useBean id="person" scope="session" class="demo.Person" type="demo.Person" >
<jsp:setProperty name="person" property="username" value="litele" />
</jsp:useBean>

Person name = ${sessionScope.person.username}


But the output is not "Person name=litele" it's like "Person name=".

I mean the object that is created is not under sessionScope....is there any thing wrong in my code??
+Pie Number of slices to send: Send
I believe you are specifying a scope that does not contain the indicated (i.e. person) object, so a new demo.Person object is created. This object has no relation to the one in request scope, other than that they are of the same class.
+Pie Number of slices to send: Send
Then why a new object is not being created??........If it was created, it should print "Person name=litele" right??

i think the object "person" of type "demo.Person" in request scope is found when jsp:useBean action is trying to locate......that's why the object is not created i think......

if this is the case........then what does "scope" attribute really mean......does it mean the scope of already existing object or the scope of the newly created objects should be in
+Pie Number of slices to send: Send
Can you show us your Person class ?
+Pie Number of slices to send: Send
 

Originally posted by sai narasimha reddy:
request.setAttribute("person",p);

then i forwarded the request to /index.jsp



use session to set the value
+Pie Number of slices to send: Send
Can you show me your total JSP code??

I think your code is right but the problem arrive where you print the name.i have run your code and it is running well.
+Pie Number of slices to send: Send
No problem now........i was using netbeans-in built-tomcat.....when i tested it with another standalone tomcat server......the code's working as it should.....


any way thank you for your replies friends......
+Pie Number of slices to send: Send
 

No problem now........i was using netbeans-in built-tomcat.....when i tested it with another standalone tomcat server......the code's working as it should.....



After seeing this post i tried this in Netbeans but even i got the same result...I did not try it in other standalone tomcat server..

Can any body say why it showing different results??

Thanks & Regards,
Sudhakar karnati
+Pie Number of slices to send: Send
Hi sudhakar, may be the tomcat in Netbeans IDE is not configured properly........don't get into such details.......the Netbeans people have to worry about it. Not you!

enjoy jsp!
Your mother was a hamster and your father was a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1275 times.
Similar Threads
HF page 416 answer for question 3 might be wrong
Question to Kathy
Doubts in Standard Actions
Problem with retreving the Attribute in jsp
Bean related exercise question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:20:33.