wood burning stoves 2.0*
The moose likes JSP and the fly likes bean vs jsp:useBean problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "bean vs jsp:useBean problem" Watch "bean vs jsp:useBean problem" New topic
Author

bean vs jsp:useBean problem

Dave Berkheimer
Greenhorn

Joined: Feb 05, 2001
Posts: 26
Hi all,

I have a little problem that I'd like to resolve just for my own gratification.

A have a simple class as follows:

package beans;

public class hellobean
{
private String name = "world";

public void setName (String name)
{
this.name = name;
}
public String getName()
{
return name;
}
}

As you can see it's a no big deal class. When I call the class with the following JSP page everything works just fine.

<html>
<jsp:useBean id="hello" class="beans.hellobean" />
<jsp:setProperty name="hello" property="name" value="dave" />
<jsp:getProperty name="hello" property="name" />
</html>

But the following page:

<%@ page language="java" import="beans.hellobean"%>

<bean name="hello" type="hellobean" introspect="yes" create="yes" scope="request"></bean>
<html>
<%=hello.getName()%> //line 5
</html>

gives me a complie error on line 5, "hello cannot be resolved", which to me implies that the bean has not been created. Yet if I remove line 5 the page compiles without any issues. Can anyone see something that I don't see? This is not critical... I just hate it when something doesn't work and I can't see why.

Thanks
Dave B.


Sun Certified Java Programmer
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60738
    
  65

<bean name="hello" type="hellobean" introspect="yes" create="yes" scope="request"></bean>


What is a <bean> tag?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dave Berkheimer
Greenhorn

Joined: Feb 05, 2001
Posts: 26
The <BEAN> tag can be seen here about one quarter of the way down the page:

http://www-306.ibm.com/software/webservers/appserv/doc/guide/asgdwp.html#HDRSAMPJSP

Dave
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60738
    
  65

That page is so old I think it might have been originally written using a stone slab and chisel.

Get yourself a copy of the JSP 2.0 Specification -- links available in JSP FAQ.
Dave Berkheimer
Greenhorn

Joined: Feb 05, 2001
Posts: 26
Well, it appears that the JSP specification no longer supports the <bean> tag. Just curious though, the bean tag allowed for introspection, a process that allowed the bean to automatically detect and then use applicable incoming parameters through the request object. Is there a comparable method that anyone knows of in the new JSP specifications? Or is it necessary now to always explicitly pass the parameters to the bean? For what it's worth, introspection seemed like a real handy-dandy thing.

Dave
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60738
    
  65

The bean tag was the beta version of <jsp:useBean> back before JSP 1.0. All this dust is making me sneeze...

Check out the permutations of <jsp:setProperty> for the functionality you seek.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean vs jsp:useBean problem
 
Similar Threads
how to access same javabean in previous web page?
Code not working
JSP and JavaBeans
JSP and JavaBeans
problem running jsp:useBean