Hi All,
I am facing a problem in calling Bean with useBean tag in
JSP in
Tomcat environment.
The problem comes when I use NetBeans 3.5.1 , internal tomcat server as well as Sun
J2EE 1.3 server - internal tomcat server.
Surprising the code perfectly works in JRun enviornment. I am putting code here......
My Bean :
public class SampleBean extends Object implements java.io.Serializable {
private static final
String PROP_SAMPLE_PROPERTY = "SampleProperty";
private String sampleProperty;
private PropertyChangeSupport propertySupport;
/** Creates new SampleBean */
public SampleBean() {
propertySupport = new PropertyChangeSupport( this );
}
public String getSampleProperty() {
return sampleProperty;
}
public void setSampleProperty(String value) {
String oldValue = sampleProperty;
sampleProperty = value;
propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY, oldValue, sampleProperty);
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertySupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertySupport.removePropertyChangeListener(listener);
}
}
My JSP :
<%@page contentType="text/html"%>
<jsp:useBean id="id" class="SampleBean" />
<html>
<head><title>JSP Page</title></head>
<body>
<table>
<tr>
<td>JSP is running!
</td>
</tr>
<td>
<jsp:getProperty name="id" property="sampleProperty" />
</td>
</tr>
</table>
</body>
</html>
I got compilation error in JSP as below :
TestJSP$jsp.java [60:1] cannot resolve symbol
symbol : class SampleBean
location: class org.apache.jsp.TestJSP$jsp
SampleBean id = null;
^
TestJSP$jsp.java [63:1] cannot resolve symbol
symbol : class SampleBean
location: class org.apache.jsp.TestJSP$jsp
id= (SampleBean)
^
TestJSP$jsp.java [68:1] cannot resolve symbol
symbol : class SampleBean
location: class org.apache.jsp.TestJSP$jsp
id = (SampleBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "SampleBean");
^
TestJSP$jsp.java [105:1] cannot resolve symbol
symbol : class SampleBean
location: class org.apache.jsp.TestJSP$jsp
out.print(JspRuntimeLibrary.toString((((SampleBean)pageContext.findAttribute("id")).getSampleProperty())));
^
4 errors
Errors compiling TestJSP.
I have put my JSP in web-base directory & SampleBean.class file in \web-inf\classes directory as per the standard structure way.
It runs perfectly in JRun, But gives problem in Tomcat...
Is there any extra setting for Tomcat ( for classpath etc though I believe above \web-inf\classes directory automatically comes in classpath) or is there any other location for
Java Beans in Tomcat....
Can any one help me out as every time I face this problem with Tomcat while code works in JRun..
Please suggest some way...
Thanks,
Manoj