File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes doubt regarding  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "doubt regarding  "jsp:useBean "  tag" Watch "doubt regarding  "jsp:useBean "  tag" New topic

doubt regarding "jsp:useBean " tag

Prakash Reddy

Joined: Apr 18, 2006
Posts: 15

I have the following servlet and JSP code

foo.Employee p = new foo.Employee();

<jsp:useBean id="person" type="foo.Employee">
Name is : <jsp:getProperty name="person" property="name" />

Assume that I have all the required classes and I am forwarding the request from the servlet to the jsp.
I want to know whether this will output "Name is Evan" or cause a runtime error.

I feel this wont work because the container tries to find the person object in the page scope since the default scope is "page". But since the person object is stored in the request scope ,it wont find it in the page scope and will hence try to create a new Employee object. But since I am not specifying the "class" attribute it fails to create the object. Hence we get an error.
But HeadFirst book says that this works fine and outputs "Name is Evan".

Can someone explain which one is correct and why ?

Prakash<br />(SCJP 1.4 96%)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

What happened when you tried it?

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: doubt regarding "jsp:useBean " tag
It's not a secret anymore!