• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

jsp:usebean

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am new to jsp.I am trying an example using jsp:usebean(taken from Professional java server programming Pg: 495).I am getting the following error.Please could someone tell me how to debug this further:
Error: 500
Location: /apps/beans.jsp
Internal Servlet Error:
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:386)
at _0002fbeans_0002ejspbeans_jsp_1._jspService(_0002fbeans_0002ejspbeans_jsp_1.java:86)

Root cause:
org.apache.jasper.JasperException
at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:207)
at org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:154)
at _0002fbeans_0002ejspbeans_jsp_1._jspService(_0002fbeans_0002ejspbeans_jsp_1.java:59)

Root cause:
java.lang.NullPointerException
at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:169)
at org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:154)
at _0002fbeans_0002ejspbeans_jsp_1._jspService(_0002fbeans_0002ejspbeans_jsp_1.java:59)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
......
The code at line 59 of _0002fbeans_0002ejspbeans_jsp_1.java is
JspRuntimeLibrary.introspect(pageContext.findAttribute("languageBean"), request);
thanks in advance

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like JSP is unable to find a class or a method that your bean is supposed to have. What does your jsp:useBean tag look like? How is the bean used?
Bill

------------------
author of:
 
Rupali Desai
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well here is the code
for the html(beans.html)
<jsp:usebean id="languageBean" scope="application" class="LanguageBean">
<jsp:setProperty name="languageBean" property="*"/>
</jsp:usebean>
<html>
<head>
<title>useBean action test result</title>
</head>
<body>
<h1>useBean action test result</h1>
<p>Hello, <jsp:getProperty name="languageBean" property="name"/>.</p>
<p>Your favourite language is
<jsp:getProperty name="languageBean" property="language"/>.</p>
<p> My comments on your language:</p>
<p><jsp:getProperty name="languageBean" property="languageComments"/>
</p>
</body>
</html>
Code :beans.jsp
<jsp:usebean id="languageBean" scope="application" class="LanguageBean">
<jsp:setProperty name="languageBean" property="*"/>
</jsp:usebean>
<html>
<head>
<title>useBean action test result</title>
</head>
<body>
<h1>useBean action test result</h1>
<p>Hello, <jsp:getProperty name="languageBean" property="name"/>.</p>
<p>Your favourite language is
<jsp:getProperty name="languageBean" property="language"/>.</p>
<p> My comments on your language:</p>
<p><jsp:getProperty name="languageBean" property="languageComments"/>
</p>
</body>
</html>
Code :LanguageBean.java
public class LanguageBean
{
private String name;
private String language;
public LanguageBean()
{
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;

}
public void setLanguage(String language)
{
this.language=language;

}
public String getLanguage()
{
System.out.println("gl");
return language;

}
public String getLanguageComments()
{
if(language.equals("Java"))
{
return "The king of OO languages";
}
else if(language.equals("C++"))
{
return "Rather too complex for some fols liking." ;
}
else if(language.equals("Perl"))
{
return "OK if you like comphrehensible code.";
}
else
{
return "Sorry,I've never heard of "+language+".";
}
}
}
 
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i guess there is a typo: replace <jsp:usebean> with <jsp:useBean>.
hope this helps,
raghav.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raghav is right, JSP is case sensitive, trips up a lot of people.
Also I suggest you put LanguageBean in a package and name the package in the useBean tag -
<jsp:useBean id="languageBean" scope="application" class="mypkg.LanguageBean">
You will also have to import it in the <%@ page directive
Tomcat acts funny when trying to look up classes not in packages.
Bill
 
Rupali Desai
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
Thanks a lot
Changing usebean to useBean solved the problem
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic