File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes calling javabean from jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "calling javabean from jsp" Watch "calling javabean from jsp" New topic
Author

calling javabean from jsp

yamini nadella
Ranch Hand

Joined: Apr 13, 2004
Posts: 257
package jsp;

import java.util.Date;
import java.text.*;

public class DateFormatBean {
private DateFormat dateFormat;
private Date date;

public DateFormatBean()
{
dateFormat = DateFormat.getInstance();
date = new Date();
}

public String getDate()
{
return dateFormat.format(date);
}
public void setDate(Date date)
{
this.date = date;
}
public void setFormat(String format)
{
this.dateFormat = new SimpleDateFormat(format);
}
}


----------------------
above is java bean script. I created a jar file for this class and kept in class path.

below is JSP
---------------------
<html>
<head><title> a simple example </title></head>
<body style = "font-family:verdana;font-size:10pt;">
<jsp:useBean id="date" class="jsp.DateFormatBean"/>

<h2>hello <%=date.getDate()%>,have a nice day!</h2>
</body>
</html>

----------
when I tried to execute above JSP from tomcat then I got error message as

HTTP Status 500 -

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

An error occurred at line: 3 in the jsp file: /jsp/projsp/datebean.jsp

Generated servlet error:
[javac] Compiling 1 source file

D:\tomcat\jakarta-tomcat-4.1.27\work\Standalone\localhost\examples\jsp\projsp\datebean_jsp.java:47: cannot resolve symbol
symbol : class DateFormatBean
location: package jsp
jsp.DateFormatBean date = null;
^



An error occurred at line: 3 in the jsp file: /jsp/projsp/datebean.jsp

Generated servlet error:
D:\tomcat\jakarta-tomcat-4.1.27\work\Standalone\localhost\examples\jsp\projsp\datebean_jsp.java:49: cannot resolve symbol
symbol : class DateFormatBean
location: package jsp
date = (jsp.DateFormatBean) pageContext.getAttribute("date", PageContext.PAGE_SCOPE);
--------------

It seems JSP file is not able to find the class file. As I kept class file in classpath also it should not give error message.

Please let me know reasons.
Adrian Pang
Ranch Hand

Joined: Feb 20, 2004
Posts: 40
I don't have access to the JDK now, but have you tried adding <%@page import="jsp.DateFormatBean"%> to the JSP?


SCJP 1.4, SCWCD 1.4, SCBCD 1.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling javabean from jsp
 
Similar Threads
problem using my class in JSP
Jsp bean error
Unable to found class
SimpleSupportTag problem
Unable to find class