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

Surprising problem in calling bean from JSP  RSS feed

 
Manoj Tyagi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put your JavaBean in a package... there are tons of problems caused by just making a JavaBean in the default package.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes make your java bean under specific package then in usebean tag give the name of your bean with package name like your_package.classname
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!