Solved

Problem with Beans

Posted on 2004-08-18
17
392 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

A Short Story about the Best File Recovery Software – Acronis True Image 2017
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

20 Experts available now in Live!

Get 1:1 Help Now