wood burning stoves 2.0*
The moose likes JSP and the fly likes The value for the useBean class attribute *class* is invalid. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "The value for the useBean class attribute *class* is invalid." Watch "The value for the useBean class attribute *class* is invalid." New topic
Author

The value for the useBean class attribute *class* is invalid.

Jesse Durham
Greenhorn

Joined: Dec 17, 2010
Posts: 6
I updated a currently working java web project by copying it, and renaming it. However, I'm getting the error in the title on a few library files. For some reason Tomcat either can't see the library file or something else is wrong and I have no idea what it could be. All of my library files are in their correct locations. Another strange thing is that I get that error MOST of the time, but if you refresh the page, a second error will also randomly show on screen saying "java.lang.ClassNotFoundException: org.apache.jsp.xs_002dtest.JSPName_jsp"

Everything I have looked into says its because these files aren't in the right locations but I am 100% sure they are. Especially considering other library files exist and they aren't throwing errors when I comment out the one that is.

Also, if i take the working project, copy it, and do nothing but re-name it in the tomcat folder, the same error is thrown.
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 199
    
    1

They might be at the corrent location but are you sure you are referencing them from the copied project correctly as well...
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Check your error log for complete error message, and potential other ones (eg null pointer exception thrown from constructor).
The standard reasons for seeing this error message

- the class is not there/has a compilation error
- the class does not have a public constructor that takes no arguments
- your class is not public


Where HAVE you put the files? You say the files are in the "right place", but we can only take your word for it. I have learned to query every assumption, because stuff you "know" is right is often the cause of the issue :-)
The class files should be either under the WEB-INF/classes directory (in their correct package structure) or in a jar file in the WEB-INF/lib directory.


Jesse Durham
Greenhorn

Joined: Dec 17, 2010
Posts: 6
They are library files, and they are in the webapps/application/WEB-INF/lib folder.

I am sure the code is correct because I can take a working application in the webapp folder, copy it, and paste it under a different name and when i try to access it, it produces the same errors. I say errors because it actually produces 2 different ones when you refresh.

This is the first...

org.apache.jasper.JasperException: /sprinthoroscopes/_uatools_helper.jsp(9,0) The value for the useBean class attribute com.upsnap.uatools.UAToolsBean is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1203)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1160)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$IncludeDirective.accept(Node.java:638)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Generator.generate(Generator.java:3365)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:315)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


This is the second...

org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:156)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:620)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.ClassNotFoundException: org.apache.jsp.sprinthoroscopes.welcome_jsp
java.net.URLClassLoader$1.run(URLClassLoader.java:200)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:188)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:618)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


the log files really aren't showing much, however the catalina log file does produce this...

java.lang.ClassNotFoundException: org.apache.jsp.sprinthoroscopes.welcome_jsp
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:618)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:619)
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Ok, so from the first message, the class it is having trouble with is: com.upsnap.uatools.UAToolsBean

Is this bean in the class path? I presume it is in one of the jar files in the WEB-INF/lib directory you mentioned.
Does it have a public constructor that takes no arguments: ie


Can this constructor throw an exception of any sort?
What happens if you try and construct the bean in a scriptlet on a jsp page?
ie: Does this work?


Sometimes Tomcat can hide the 'true' error message behind the "value is invalid" message. Constructing the bean manually might reveal it for you.
Jesse Durham
Greenhorn

Joined: Dec 17, 2010
Posts: 6
The public constructor is written exactly as you wrote it.

no exceptions can be thrown.


I feel its a good idea to mention, to alleviate any issues about the code being incorrect.. the build works fine when i use netbeans' localhost. Building the bean by itself produces no errors. This error only occurs when I pushed it to live tomcat. Clearly there is some reason why live tomcat can't find these library files. The problem is not the code itself.

In order to construct the bean in a scriptlet page, i had to comment out the bean declarations throwing all of these errors...



but all that happened was produce this output...



which to me basically says.. hey you didn't declare your bean. Yeah well obviously, because when i do, it errors out with the errors i pasted earlier
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Jesse Durham wrote:
but all that happened was produce this output...



which to me basically says.. hey you didn't declare your bean. Yeah well obviously, because when i do, it errors out with the errors i pasted earlier


Really? Because to me it says it can't find the class UAToolsBean. To me thats a ClassNotFoundException.

How about Class.forName("com.upsnap.uatools.UAToolsBean"); ?

My take on this:
The value is invalid, because it can't find that Class.
That class is obviously not deployed where you think it is, or the jar file is corrupt and unreadable.
The fact that it runs under Netbeans actually convinces me more of this. NetBeans will be doing something automatically (adding the project to the classpath) which you haven't done under the live Tomcat deployment.

I would suggest starting with a brand new blank web application under Tomcat.
Create a JSP with JUST that useBean tag in it.
Add the jar file with the class in it into the WEB-INF/lib directory.
See if it works.


One other thing that just struck me: does the UAToolsBean class have any dependencies that may not be satisfied under Tomcat? maybe you are missing some other jar files? I would have thought it would give a different exception, but that might bear some investigation...

Jesse Durham
Greenhorn

Joined: Dec 17, 2010
Posts: 6
All of your ideas sound like they could be possible with one huge exception.

This code and these jars WORK under an existing project.

I literally took a project in the webapps folder named horoscopes, copied it, and renamed it sprinthoroscopes. And tomcat throws these errors when trying to view sprinthoroscopes. but it works fine when viewing horoscopes.

Same code, identical project, just a different folder name. One works, one does not. So i can't believe its a corrupt .jar file or the code is wrong or anything like that. The problem is not the code, the problem is tomcat not seeing jar files on new webapps. otherwise it wouldn't work in either project.

I 100% agree the problem is tomcat not seeing the jar file. The question is.. why can it see it in one project, but when i make an EXACT COPY of that project under a different name, does it suddenly NOT see the jar anymore?

The fact that it runs under Netbeans actually convinces me more of this. NetBeans will be doing something automatically (adding the project to the classpath) which you haven't done under the live Tomcat deployment.


This is exactly right. There is some step being missed when adding new webapps to tomcat that I am missing, that has to do with tomcat seeing .jar files in the WEB-INF/lib. I need to figure out what that step is, because everything I have read and seen says it should be as simple as having the files in the lib folder. Clearly that is not the case.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Hmmm.
We'll try one more stab :

Does it recognise your copied web application as a web app in itself? Maybe it is not deploying it as a seperate web application?
Depending on your Tomcat settings, it may or may not pick up the new web application.
You should be able to find out that information from the Tomcat Management console.

This diagnostic page may help



Check that the ContextPath is actually the ContextPath you think your web application is deployed under.
It may be loading your page under the Root web application, but honestly I'm just grasping at straws right now :-)

I dunno I can be much more help after this. It sounds like it should work, but obviously doesn't. I'm stumped.
Jesse Durham
Greenhorn

Joined: Dec 17, 2010
Posts: 6
I'm not totally familiar with the manager console. How can i use it to check the context path? I will say though, when looking under all applications under tomcat, the new copy/pasted app is not listed.

*edit*

after tinkering around with the manager ive noticed that the manager does not list the new web applications. So clearly things aren't getting deployed correctly. So i investigated further and found the manager command to manually deploy.. but it returns with this error...

FAIL - Failed to deploy application at context path /my/path/to/app



I didn't install this version of tomcat it was installed by an employee before me... is it possible there is some tomcat settings file that was altered to halt deployment in some way?
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Ok, so my current theory is that your "copied" web application was not actually deployed.
The page request you made was being handled by the "default" or "root" web application which doesn't have that required class in it.

But given that theory I'm certain how it managed to find your JSP page in the first place, rather than give a 404 error.

So to help confirm this, check the Tomcat Configuration files.
Check out server.xml in the [TOMCAT]/conf directory. Specifically you are looking for the "autodeploy" attribute of the <host>
Presumably this has been set to false which is why copy/pasting the directory would not work.

I would recommend you check out the Tomcat Documentation for details.

How to progress next depends upon how it is currently set up. Has the previous person defined Context entries in server.xml, or are there seperate context.xml files in sub-directories under [TOMCAT]/conf.

Hopefully this can at least set you on the right track.

cheers,
Stefan
Jesse Durham
Greenhorn

Joined: Dec 17, 2010
Posts: 6
After checking out the server.xml file it looks like the context paths are defined inside it. I believe this was the problem. We added the path to the server.xml file and it seems to be displaying the pages now.

Thanks a ton for the help Stefan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The value for the useBean class attribute *class* is invalid.