Desperately looking for help with:The value for the useBean class attrib...

hello everybody!

I am looking up in forums since this morning in order to fix this problem with java beans but i still didn't find a solution! I hope somebody in this forum can help me! I write down exactly everything I did with the hope that we will soon leave in the forum a sort of tutorial for fixing this common problem (I read a lot of topics without a clear solution)..

What I use : TOMCAT 5.5.20, JDK 1.5.0_11 and ECLIPSE 3.2.1 with WTP. My OS is Windows XP.

What I did step-by-step:

1) Create new project "bean2" in eclipse+WTP: Dynamic Web Project. I've set Target Runtime to Apache Tomcat 5.5 and used the <custom> configuration. I left also the default settings for content directory (WebContent) and Java Directory Source (src).

2) Once the project has been created, i modified the Build path in order to have .class files created in the proper directory. In project explorer i expanded Java Resources: src until i could see a library (e.g. Web App Libraries) and right click on it. Then I selected build path ->Configure build path. Then in the source folder i choosed the Source palette and there i changed the default output folder to "bean2/WebContent/WEB-INF/classes".

3) I created a new java class in a package called user. Right click on Java REsources->New->Class. Package: user Class: User

The code of the bean User.java is:

package user;

publicclass User{

protected String lastName;

protected String firstName;

public User(){

}

public String getLastName(){

return lastName;

}

publicvoid setLastName(String lname){

lastName = lname;

}

public String getFirstName(){

return firstName;

}

publicvoid setFirstName(String fname){

firstName = fname;

}

}

4) Then I created an handoff1.jsp file in the WebContent folder. The content of the file is:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<%@ pageimport ="user.*" %>

<jsp:useBean id="handoff" scope="session" class="user.User" />

This is the setting page! <% handoff.setFirstName("George"); %>

Then a handoff2.jsp file (note that the code is copied from a book):

<%@ pageimport ="user.*" %>

<jsp:useBean id="handoff" scope="session" class="user.User" />

This is the getting page!

handoff= <%= handoff.getFirstName() %>

]

5) Finally I started tomcat by clicking on startup.bat (in the bin folder) and pointed the browser to http://localhost:8080/bean2/WebContent/handoff1.jsp

6) What I got is this:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfillingthis request.

exception

org.apache.jasper.JasperException: /WebContent/handoff1.jsp(4,0) The valuefor the useBeanclass attribute user.User is invalid.

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

org.apache.jasper.JasperException: /WebContent/handoff1.jsp(4,0) The valuefor the useBeanclass attribute user.User is invalid.

org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)

org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)

org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)

org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)

org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)

org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)

org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)

org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)

org.apache.jasper.compiler.Node$Root.accept(Node.java:456)

org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)

org.apache.jasper.compiler.Generator.generate(Generator.java:3320)

org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.

So: What did I do wrong? I wasted hours and hours trying to fix this but without a result.. Can you help me please?

Thanks you 10^999999!! :)

[6666 byte] By [smokinga] at [2007-11-26 17:57:01]
# 1
Hi smoking, Did you compile the Java file? I tried your code, I got the same error message when the file was not compiled. But after compling the User Java Bean into a class file, it worked.
appy77a at 2007-7-9 5:10:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Another thing and probably [Off-Topic] , you could use

<jsp:setProperty name="handoff" property="firstName" value="George"/>

instead of

<% handoff.setFirstName("George"); %>

and also

<jsp:getProperty name="handoff" property="firstName" />

instead of

<%= handoff.getFirstName() %>

appy77a at 2007-7-9 5:10:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

hello and 1st of all thanks 4 your answer!

it's something strange but if I just compile the code with the option -d which points to the WEB-INF/classes directory, and then run the server and the program, i get the same error..

I solved by running the program directly under eclispe (right click on the jsp page->Run as->run on server and then selecting tomcat 5.5)...

:-O

For the moment i go on like this, as the code is for sure correct!

Bye and thank you again!

smokinga at 2007-7-9 5:10:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I don't know if you are familiar with Ant build,

Ant or tools like Maven and other similar tools, make it much easier to manage the building process for a project.

They also come with robust tasks to compile the Java classes in a project.

You may want to take a look at Ant because compiling individual files will be a PITA.

-Cheers

appy77a at 2007-7-9 5:10:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...