Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with jsp:useBean

 
Sai Narasimha Reddy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sai Narasimha Reddy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us your Person class ?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sai narasimha reddy:
request.setAttribute("person",p);

then i forwarded the request to /index.jsp



use session to set the value
 
mimi chatterjee
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sai Narasimha Reddy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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......
 
sudhakar karnati
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sai Narasimha Reddy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic