• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean

 
Arvind Chavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a sample jsp to use a bean.It is as follows
<%@ page language="java" session="false" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
This is an example of use of JavaBeans.
<jsp:useBean id="per" scope="page"class="Person"/>
</BODY>
</HTML>
I was getting following error when I access using
http://localhost:8080/TestApp/jsp/useBean.jsp
============================== ERROR ============
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 6 in the jsp file: /jsp/useBean.jsp
=================================================
In fact I have placed the class file for Person.java under TOMCAT_HOME/TestApp/WEB_INF/classes, as it does not have package.

The above JSP complies fine if I make Person class part of a package(in my example it is "sungard") and store the class in TOMCAT_HOME/TestApp/WEB_INF/classes/sungard, and change jsp:useBean tag as follows
<jsp:useBean id="per" scope="page"class="sungard.Person"/>

Why is this?.Do I need to configure something else?.I presumed that JSP complier(Jasper) will resolve the class file location using packagaename starting at WEB-INF/classes
Thanks,
Arvind
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has to do with a common ClassLoader bug. Seems if you don't have a package, the ClassLoader assumes the Bean is in the same package as the class you are in. The package is diferent depending on your server. For you it's apparently jsp.
 
Arvind Chavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carl,
Your explanation does help in knowing what is teh cause.
I tried to put the class file for the bean every posssible place in the webapp ,just to see from where it could pick, but it did'nt.Looks like only way was using package.
Thanks,
Arvind
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic