• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Surprising problem in calling bean from JSP

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
No holds barred. And no bars holed. Except this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic