tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 45153] New: Javabean not accessible to jsp until placed in a package.
Date Fri, 06 Jun 2008 20:51:06 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=45153

           Summary: Javabean not accessible to jsp until placed in a
                    package.
           Product: Tomcat 6
           Version: unspecified
          Platform: Macintosh
        OS/Version: Mac OS X 10.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Servlet & JSP API
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: d.brownjr@juno.com


I am using version 6.0.16 of tomcat and the problem may be version dependent.
The problem I experienced is, if a bean is not contained within a package, the
bean is not accessible from a JSP.

Without a package specified in the bean class and with the bean class file in
the classes folder, the following exceptions occurred. The condition was not
resolved until a "package foo;" statement was added to the bean class and the
class file was placed in the "classes/foo" folder. 

This is the error when the useBean standard action was used:
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /testJSTL3.jsp(12,0) The value for the
useBean class attribute TestBean1 is invalid.
        at
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
...

This is the error when a scriptlet was used:
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 7 in the jsp file: /testJSTL3.jsp
TestBean1 cannot be resolved to a type
4: <%
5:     String [] movieList = {"Amelie", "Returrn of the King", "Mean Girls"};
6:     request.setAttribute("movieList", movieList);
7:     TestBean1 myBean = new TestBean1();


This is the error when the page directive and import attribute were used in the
jsp.
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 6 in the generated java file
The import TestBean1 cannot be resolved


The following is a failing version of the code:

TestBean1.java:

public class TestBean1 {
    private String prop1;
    private int prop2;

    public TestBean1() {
    }

    public String getProp1() {
        return prop1;
    }

    public void setProp1(String newProp) {
        prop1 = newProp;
    }

    public int getProp2() {
       return prop2;
    }

   public void setProp2(int newProp) {
      prop2 = newProp;
   }
}

testBean.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="TestBean1" %>
<html><body>
<%
    String [] movieList = {"Amelie", "Returrn of the King", "Mean Girls"};
    request.setAttribute("movieList", movieList);
    TestBean1 myBean2 = new TestBean1();
    myBean2.setProp1("This is a String a myBean property");
    myBean2.setProp2(87654321);
    request.setAttribute("myBean2", myBean2);
%>
<jsp:useBean id="myBean" class="TestBean1" scope="request" />
<jsp:setProperty name="myBean" property="prop1" value="This is a String
property." />
<jsp:setProperty name="myBean" property="prop2" value="12345678" />

<%--  forEach looks through scope maps for attribute specified in items
attribute --%>
<table>
    <c:forEach var="s" items="${movieList}" varStatus="movieNum">
        <tr><td>Movie ${movieNum.count}: ${s}</td></tr>
    </c:forEach>  
    <tr><td>Prop1: ${myBean.prop1}</td></tr>
    <tr><td>Prop2: ${myBean.prop2}</td></tr>
    <tr><td>Last Row</td></tr> 
</table>
</body></html>



The following is a working version of the code:

TestBean1.java:

package foo;

public class TestBean1 {
    private String prop1;
    private int prop2;

    public TestBean1() {
    }

    public String getProp1() {
        return prop1;
    }

    public void setProp1(String newProp) {
        prop1 = newProp;
    }

    public int getProp2() {
       return prop2;
    }

   public void setProp2(int newProp) {
      prop2 = newProp;
   }
}

testBean.jsp:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="foo.TestBean1" %>
<html><body>
<%
    String [] movieList = {"Amelie", "Returrn of the King", "Mean Girls"};
    request.setAttribute("movieList", movieList);
    TestBean1 myBean2 = new foo.TestBean1();
    myBean2.setProp1("This is a String a myBean property");
    myBean2.setProp2(87654321);
    request.setAttribute("myBean2", myBean2);
%>
<jsp:useBean id="myBean" class="foo.TestBean1" scope="request" />
<jsp:setProperty name="myBean" property="prop1" value="This is a String
property." />
<jsp:setProperty name="myBean" property="prop2" value="12345678" />

<%--  forEach looks through scope maps for attribute specified in items
attribute --%>
<table>
    <c:forEach var="s" items="${movieList}" varStatus="movieNum">
        <tr><td>Movie ${movieNum.count}: ${s}</td></tr>
    </c:forEach>  
    <tr><td>Prop1: ${myBean.prop1}</td></tr>
    <tr><td>Prop2: ${myBean.prop2}</td></tr>
    <tr><td>Last Row</td></tr> 
</table>
</body></html>


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message