Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean vs jsp:useBean problem

 
Dave Berkheimer
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<bean name="hello" type="hellobean" introspect="yes" create="yes" scope="request"></bean>


What is a <bean> tag?
 
Dave Berkheimer
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic