Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 30th, 2006, 08:55 AM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calling bean from jsp page

Hi,

I have my java bean code as:

public class SimpleBean {

  private String message = "No message specified";

  public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
    this.message = message;
  }

}

and I have my jsp code as:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Reusing JavaBeans in JSP</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="test" class="SimpleBean" />
<jsp:setProperty name="test" property="message" value="Hello WWW" />
<H1>Message: <I>
<jsp:getProperty name="test" property="message" />
</BODY>
</HTML>

I am getting the error as:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 17 in the jsp file: /beanTest.jsp
Generated servlet error:
D:\jboss-3.2.7\server\im\work\jboss.web\localhost\my\org\ap ache\jsp\beanTest_jsp.java:58: cannot find symbol
symbol : class SimpleBean
location: class org.apache.jsp.beanTest_jsp
      SimpleBean test = null;
      ^


An error occurred at line: 17 in the jsp file: /beanTest.jsp
Generated servlet error:
D:\jboss-3.2.7\server\im\work\jboss.web\localhost\my\org\ap ache\jsp\beanTest_jsp.java:60: cannot find symbol
symbol : class SimpleBean
location: class org.apache.jsp.beanTest_jsp
        test = (SimpleBean) _jspx_page_context.getAttribute("test", PageContext.PAGE_SCOPE);
                ^


An error occurred at line: 17 in the jsp file: /beanTest.jsp
Generated servlet error:
D:\jboss-3.2.7\server\im\work\jboss.web\localhost\my\org\ap ache\jsp\beanTest_jsp.java:62: cannot find symbol
symbol : class SimpleBean
location: class org.apache.jsp.beanTest_jsp
          test = new SimpleBean();
                     ^


An error occurred at line: 21 in the jsp file: /beanTest.jsp
Generated servlet error:
D:\jboss-3.2.7\server\im\work\jboss.web\localhost\my\org\ap ache\jsp\beanTest_jsp.java:72: cannot find symbol
symbol : class SimpleBean
location: class org.apache.jsp.beanTest_jsp
      out.write(org.apache.jasper.runtime.JspRuntimeLibr ary.toString((((SimpleBean)_jspx_page_context.find Attribute("test")).getMessage())));
                                                                        ^
4 errors



    org.apache.jasper.compiler.DefaultErrorHandler.jav acError(DefaultErrorHandler.java:84)
    org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:332)
    org.apache.jasper.compiler.Compiler.generateClass( Compiler.java:437)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:497)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:476)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:464)
    org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:511)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:295)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:75)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.30 logs.

Can anyone help me out why mistake I have doen in above program


Reply With Quote
  #2 (permalink)  
Old January 30th, 2006, 06:42 PM
Authorized User
 
Join Date: Jan 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to longjava
Default

The errors seem to me that your result complied byte-code (SimpleBean.class) did not get copied in to the right place. Since your bean class SimpleBean did not have a package name, therefore it is located in the default package. Make sure your result compile byte-code of your beans get copied to WEB-INF/classes directory if your bean classes do not have package name defined. If your beans have a package name defined then copy the result compile byte-code to the package name accordingly.

For example:

// without a package name defined
class A
{
}
// copy the A.class to WEB-INF/classes directory

// with a package name is defined
package mycompany.myapp.mymodule;
class B
{
}
// copy the B.class to the WEB-INF/classes/mycompany/myapp/mymodule directory



Reply With Quote
  #3 (permalink)  
Old January 31st, 2006, 01:27 AM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for the reply. I tried the same but ended with the same error. This is making me mad..............



Reply With Quote
  #4 (permalink)  
Old January 31st, 2006, 05:18 AM
Authorized User
 
Join Date: Jan 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to longjava
Default

How do you jar you war file? Can I see the content of it? Since you are using JBoss Application server I wonder what type of deployment archive file you deploy with your app? war file or ear file??

Reply With Quote
  #5 (permalink)  
Old February 13th, 2006, 05:12 AM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What files are in your WEB-INF/classes directory? SimpleBean.class needs to be in there -- is it?

Jon Emerson
http://www.jonemerson.net/
Reply With Quote
  #6 (permalink)  
Old February 17th, 2006, 04:07 AM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What files are in your WEB-INF/classes directory? SimpleBean.class needs to be in there -- is it?
You also can make the class to jar,and copy it into WEB_INF/classes directory



JAVA Email
http://www.wisesoft.biz/
Reply With Quote
  #7 (permalink)  
Old May 10th, 2006, 09:15 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Despite the time lag, I thought I'd post a response. I'm having the exact same problem running through a JSP tutorial.

The section that calls the bean:
<jsp:useBean id="myHobby" scope="session" class="Hobby"/>
<c:when test="${true}" >
  <h2>Your favorite hobby is ${myHobby["myHobby"]}!</h2>
</c:when>
</c:choose>

Classes in WEB-INF/Classes: Hobby.class

Translated jsp that applies:
      Hobby myHobby = null;
      synchronized (session) {
        myHobby = (Hobby) _jspx_page_context.getAttribute("myHobby", PageContext.SESSION_SCOPE);
        if (myHobby == null){
          myHobby = new Hobby();
          _jspx_page_context.setAttribute("myHobby", myHobby, PageContext.SESSION_SCOPE);

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

Generated servlet error:
    [javac] C:\Sun\AppServer\domains\domain1\generated\jsp\j2e e-modules\hello1\org\apache\jsp\luckyNumber_jsp.java :69: cannot find symbol
    [javac] symbol : class Hobby
    [javac] location: class org.apache.jsp.luckyNumber_jsp
    [javac] Hobby aHobby = null;
    [javac] ^


Generated servlet error:
    [javac] C:\Sun\AppServer\domains\domain1\generated\jsp\j2e e-modules\hello1\org\apache\jsp\luckyNumber_jsp.java :71: cannot find symbol
    [javac] symbol : class Hobby
    [javac] location: class org.apache.jsp.luckyNumber_jsp
    [javac] aHobby = (Hobby) _jspx_page_context.getAttribute("aHobby", PageContext.SESSION_SCOPE);
    [javac] ^


Generated servlet error:
    [javac] C:\Sun\AppServer\domains\domain1\generated\jsp\j2e e-modules\hello1\org\apache\jsp\luckyNumber_jsp.java :73: cannot find symbol
    [javac] symbol : class Hobby
    [javac] location: class org.apache.jsp.luckyNumber_jsp
    [javac] aHobby = new Hobby();
    [javac] ^


Generated servlet error:
    [javac] Note: C:\Sun\AppServer\domains\domain1\generated\jsp\j2e e-modules\hello1\org\apache\jsp\luckyNumber_jsp.java uses unchecked or unsafe operations.


Generated servlet error:
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 3 errors


My attempts to import the folder (which I know should be unnecessary):
<@page import="classes.*">
<@page import="classes.Hobby">
<@page import="WEB-INF.classes.*">



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling jsp from xslt rajesh_css XSLT 1 September 18th, 2008 02:54 AM
Jsp,bean iishu JSP Basics 0 November 17th, 2007 11:21 AM
connecting DB with JSP using Java Bean Q4Java Java Databases 1 May 7th, 2007 03:44 AM
calling an oracle procedure from a jsp page jasonteaboy Pro JSP 0 November 20th, 2006 03:06 PM
Retrieve Data from Java Bean to JSP page Nirav Joshi JSP Basics 1 August 24th, 2005 07:45 AM



All times are GMT -4. The time now is 10:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.