| 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
|
 |
 |
|
|
subject: calling javabean from jsp
|
|
|