aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes problem with jsp:useBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "problem with jsp:useBean" Watch "problem with jsp:useBean" New topic
Author

problem with jsp:useBean

Sai Narasimha Reddy
Greenhorn

Joined: Dec 13, 2006
Posts: 23
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??


Sai Narasimha
Dee Brown
Ranch Hand

Joined: Jun 14, 2008
Posts: 94
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

Joined: Dec 13, 2006
Posts: 23
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

Can you show us your Person class ?


[My Blog]
All roads lead to JavaRanch
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Dec 03, 2007
Posts: 26
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

Joined: Dec 13, 2006
Posts: 23
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

Joined: May 03, 2007
Posts: 93
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

Joined: Dec 13, 2006
Posts: 23
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!
 
jQuery in Action, 2nd edition
 
subject: problem with jsp:useBean