• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp:usebean  RSS feed

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

 
William Brogden
Author and all-around good cowpoke
Rancher
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+".";
}
}
}
 
Raghav Sam
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
Rancher
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!