File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes jsp action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp action " Watch "jsp action " New topic

jsp action

geet kaur
Ranch Hand

Joined: Sep 03, 2008
Posts: 79

can anyone please
<jsp:usebean id="what shud be the value here??" the name of the attribute which we defined in the servlet class ??and will this create the bean object?>
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Why are you even using <jsp:useBean> in the first place?

If you have set the scoped variable in the servlet controller, you can just access it by name directly.

For example, if in your servlet controller you wrote:
You can access this in the JSP via: ${message}

The same thing works for objects like beans. If you name the scoped variable myBean, for example, and it has a property accessor such as getWhatever(), that property can be accessed via: ${myBean.whatever}

The useBean action does not need to be used to enable such access.

[Asking smart questions] [About Bear] [Books by Bear]
geet kaur
Ranch Hand

Joined: Sep 03, 2008
Posts: 79
no i am just going through the scriptless jsp!!(head first) just wanted to know what exactly is happening behind
Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
With JSP the tags get translated into java code

<jsp:useBean id="myBean" class="com.mypackage.MyBean"/>

gets roughly translated into java as

So you get a scriptlet variable declared on the page.
If the value already exists as an attribute, it will use that value, otherwise it creates a new object.
Full details available in the jsp reference

I agree. Here's the link:
subject: jsp action
It's not a secret anymore!