Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use a javaBean in a jsp  RSS feed

 
Adam Dear
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to connect to a java bean from a .jsp, but the server is giving an HTTP Status 500 error. Can someone tell me what might be wrong.
Here is my code:

CalculatorBean:
public class CalculatorBean
{
public int doubleIt(int number)
{
return 2 * number;
}
}

SimplePage.jsp:
<jsp:useBean id="theBean" class="CalculatorBean"/>
<html>
<head>
</head>
<body>
<%
int i = 4;
int j = theBean.doubleIt(i);
out.println("2*4="+j);
%>
</body>
</html>

Here is the nasty looking error that tomcat gives:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 1 in the jsp file: /SimplePage.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 5.0\work\Catalina\localhost\myApp\org\apache\jsp\SimplePage_jsp.java:42: cannot find symbol
symbol : class CalculatorBean
location: class org.apache.jsp.SimplePage_jsp
CalculatorBean theBean = null;
^


An error occurred at line: 1 in the jsp file: /SimplePage.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 5.0\work\Catalina\localhost\myApp\org\apache\jsp\SimplePage_jsp.java:44: cannot find symbol
symbol : class CalculatorBean
location: class org.apache.jsp.SimplePage_jsp
theBean = (CalculatorBean) _jspx_page_context.getAttribute("theBean", PageContext.PAGE_SCOPE);
^


An error occurred at line: 1 in the jsp file: /SimplePage.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 5.0\work\Catalina\localhost\myApp\org\apache\jsp\SimplePage_jsp.java:46: cannot find symbol
symbol : class CalculatorBean
location: class org.apache.jsp.SimplePage_jsp
theBean = new CalculatorBean();
^
3 errors

Can someone offer any suggestions as to what the problem is?

Thanks-
A
 
Ajith Anand
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jsp compiler is unable to find the class CalculatorBean.

Is your CalculatorBean.class created in a directory myApp\WEB-INF\classes...that is where your jsp compiler looks for the javabean classes ...Make it a point your CalculatorBean.class is there....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:useBean id="theBean" class="CalculatorBean"/>


All classes referenced in a web application must be in a package other than the default or the class loader will fail to find them.
 
Adam Dear
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help, It is working now
[ November 02, 2004: Message edited by: Adam Dear ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!