Solved

Problem with Beans

Posted on 2004-08-18
17
394 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

For months I had no idea how to 'discover' the IP address of the other end of a link (without asking someone who knows), and it drove me batty. Think about it. You can't use Cisco Discovery Protocol (CDP) because it's not implemented on the ASAs.…
Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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