Solved

Problem with Beans

Posted on 2004-08-18
17
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
getting param value 7 59
Is possible to make a jsp script work with oracle wallet? 7 106
countXY challenge 28 171
withoutString  challenge 40 216
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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