Solved

Problem with Beans

Posted on 2004-08-18
17
393 Views
Last Modified: 2010-04-01
I am new to JSP, i m trying to build a simple application, using beans. This application is made with reference to Sun's Tutorials. I am using Tomcat to run JSP. The problem is with an error which i am not able to figure out. It says that the Bean class is not found, although its placed in the WEB-INF folder. I have used the package approach, but the error still persist. Here are the errors, first is the exception report and the secnod one is the root cause;



type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: NameHandler
      at org.apache.jasper.compiler.BeanRepository.getBeanType(BeanRepository.java:183)
      at org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerator.java:102)
      at org.apache.jasper.compiler.JspParseEventListener$GeneratorWrapper.generate(JspParseEventListener.java:834)
      at org.apache.jasper.compiler.JspParseEventListener.generateAll(JspParseEventListener.java:241)
      at org.apache.jasper.compiler.JspParseEventListener.endPageProcessing(JspParseEventListener.java:197)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:215)
      at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:552)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:177)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:189)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
      at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
      at java.lang.Thread.run(Thread.java:536)


root cause

java.lang.ClassNotFoundException: NameHandler
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1394)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1243)
      at org.apache.jasper.compiler.BeanRepository.getBeanType(BeanRepository.java:181)
      at org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerator.java:102)
      at org.apache.jasper.compiler.JspParseEventListener$GeneratorWrapper.generate(JspParseEventListener.java:834)
      at org.apache.jasper.compiler.JspParseEventListener.generateAll(JspParseEventListener.java:241)
      at org.apache.jasper.compiler.JspParseEventListener.endPageProcessing(JspParseEventListener.java:197)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:215)
      at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:552)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:177)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:189)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
      at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
      at java.lang.Thread.run(Thread.java:536)

0
Comment
Question by:NadirMaroof
  • 10
  • 7
17 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 11838682
> It says that the Bean class is not found, although its placed in the WEB-INF folder

is the class in:

  WEB-INF/classes/your/package/NameHandler.class

?

It needs to be in WEB-INF/classes, not just WEB-INF

0
 
LVL 35

Expert Comment

by:TimYates
ID: 11838684
Or, if it is in a jar, put the jar into

  WEB-INF/lib
0
 

Author Comment

by:NadirMaroof
ID: 11838733
ya i have followed the right path, its
E:\JSP Learning\Using Beans\WEB-INF\classes\hello\NameHandler.class

the package name is hello.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11838895
and your tomcat context is set to:

    E:\JSP Learning\Using Beans\

?

Can you try a directory without spaces in it?  (Java doesn't like spaces in filenames as a general rule) :-(

If that doesn't help, can you post your bean code?

0
 

Author Comment

by:NadirMaroof
ID: 11838929
yes my tomcat context is set to;
E:\JSPLearning

i have removed the spaces, UsingBeans is a folder inside JSPLearning, i have not mentioned UsingBeans in the context. My bean code is as follows.

package hello;

public class NameHandler{

private String username;

public NameHandler(){
      username=null;}

public void setUserName(String name){
      username = name;}

public String getUserName(){
      return username;}

}
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11839075
> i have not mentioned UsingBeans in the context

E:\JSP Learning\Using Beans\WEB-INF\classes\hello\NameHandler.class

should be:

E:\JSP Learning\WEB-INF\classes\hello\NameHandler.class

then (I think)
0
 

Author Comment

by:NadirMaroof
ID: 11839117
oh sorry, i thought that if JSPLearning is mentioned in the context, then its enough, now i have placed the WEB-INF folder to;

E:\JSP Learning\WEB-INF\classes\hello\NameHandler.class

but the first error still persist,

type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Cannot find any information on property 'username' in a bean of type 'hello.NameHandler'
      at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:702)
      at org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerator.java:104)
      at org.apache.jasper.compiler.JspParseEventListener$GeneratorWrapper.generate(JspParseEventListener.java:834)
      at org.apache.jasper.compiler.JspParseEventListener.generateAll(JspParseEventListener.java:241)
      at org.apache.jasper.compiler.JspParseEventListener.endPageProcessing(JspParseEventListener.java:197)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:215)
      at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:552)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:177)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:189)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
      at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
      at java.lang.Thread.run(Thread.java:536)


0
 
LVL 35

Expert Comment

by:TimYates
ID: 11839174
> but the first error still persist,

that's a different error, surely?

> Cannot find any information on property 'username' in a bean of type 'hello.NameHandler'

You have called it

"userName" in the bean, and (I'm guessing) "username" in the JSP ;-)

Tim
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Expert Comment

by:TimYates
ID: 11839178
> public void setUserName(String name){

...

> public String getUserName(){

See?  Capital "N" in name for the get and set method ;-)

Tim
0
 

Author Comment

by:NadirMaroof
ID: 11839204
hey, i had two errors, if u look at my first post. And i really dont understand that what difference does it make with capital N in the method name ;-)

can u plz elaborate a little, i have used "username" everywhere, which is an attribute of type String in my bean.
0
 

Author Comment

by:NadirMaroof
ID: 11839231
sorry Tim, it worked, but still i would like u to explain why this has happened. the program is running fine now.
0
 

Author Comment

by:NadirMaroof
ID: 11839243
and 'U' is also in caps, why its not making much effect ? why only 'N'
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11839250
when you use JSP to get an attribute (or set one) using JSP tags, it uses reflection to call the correct method name.  So for getters and setters, if you have a String variable called

    myVariable

then you need to write a method which looks like

  public void getMyVariable()

and one which looks like

  public String setMyVariable( String var )

Notice how you make the first letter after "get" or "set" capital.

So for "username", you need to write:

  public String getUsername(){

and

  public void setUsername(String name){

Notice, the capital "U" (as it is after "get" and "set"), but the lowercase "n", as you want to call your variable "username", NOT "userName"

Then,

    <jsp:getProperty name="username" property="username"/>

will work :-)

>  hey, i had two errors, if u look at my first post.

Yeah, both those errors are because tomcat couldn't find the "NameHandler" class...  The error you posted just now, is because it cannot find the method "getUsername" (or setUsername), as you had a capital "N" in the method names

Hope this explains it a bit better!!

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11839252
Phew!  What a lot of typing for 20 points ;-)
0
 
LVL 35

Accepted Solution

by:
TimYates earned 20 total points
ID: 11839269
Yay!  Glad it worked :-)

When you get an exception like the first one you posted, the "root cause" is often more helpful than the exception it shows first!

    java.lang.ClassNotFoundException: NameHandler

Showed us that tomcat couldn't locate the class (that's how I knew the class was in the wrong place) ;-)

Good luck with it all!!

Tim
0
 

Author Comment

by:NadirMaroof
ID: 11839299
thank you Tim, you really helped me, well ya it was a bit for 20 points, but thanx anyways :-)

cheers
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11839343
No worries :-)  Glad I could help :-)

Good luck with it!!

Tim
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Export JSON response data to Excel in IE9 3 67
EJB MDB example 4 79
Spring MVC - sending raw charset to backend 3 188
how to hide hide popup page refresh second time? 10 111
Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now