tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "L Rutker" <lrut...@hotmail.com>
Subject Re: <jsp:useBean /> Scope Bug in 4.01 !
Date Mon, 11 Feb 2002 15:42:44 GMT
Hi,
I wrote 2 test JSPs to demonstrate the problem.

Here are the JSPs:
TestScope.jsp:
<%@ page language="java"  import="java.util.*, javax.swing.*"
errorPage="error.jsp"%>
<%
     boolean isJLabel= false;
     if( request.getParameter("type") !=null &&
request.getParameter("type").equals("JLabel")) {
         isJLabel=true;
     }
%>
<% if (isJLabel) { %>
     <jsp:useBean id="jl" class="javax.swing.JLabel" scope="request"/>
<%} else { %>
     <jsp:useBean id="vec" class="java.util.Vector" scope="request"/>
<% } %>
<% if(isJLabel) {%>
     <%-- does not work anywhere --%>
     <%--= jl --%>
     <%-- works in Tomcat and not WL 6.1 --%>
     <%= "<br /> am in  isJLabel \n"%>
     <jsp:getProperty name="jl" property="text" />
<% } else {%>
     <%= "<br /> am in  else \n"%>
<% } %>

and TestScopeTester.jsp:
<%@ page language="java"  import="java.util.*, javax.swing.*"
errorPage="error.jsp"%>
<%
     javax.swing.JLabel jl = new javax.swing.JLabel("hello world");
     request.setAttribute("jl", jl);
     Vector v = new Vector();
     request.setAttribute("vec", new Vector());
%>
<jsp:forward page="TestScope.jsp?type=JLabel" />

In Weblogic 6.1 on linux I get:
weblogic.servlet.jsp.JspException: (line 18): "jl" is not a defined bean
variable on this page (rest of stackTrace ommited)

yet it works on Tomcat (and compiles in JBuilder 5).
Who is right?

Note that only when accessing the bean via a jsp:getProperty /> does it work
in Tomcat 4.01. Trying to access it via <%=jl%> will not compile for the
same reason it wont in WL.

here are the tomcat generated src files:

package org.apache.jsp;

import java.util.*;
import  javax.swing.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;


public class _0002fTestScope_jsp extends HttpJspBase {

     // begin [file="/TestScope.jsp";from=(8,4);to=(8,69)]
     // end
     // begin [file="/TestScope.jsp";from=(10,4);to=(10,68)]
     // end

     static {
     }
     public _0002fTestScope_jsp( ) {
     }

     private static boolean _jspx_inited = false;

     public final void _jspx_init() throws
org.apache.jasper.runtime.JspException {
     }

     public void _jspService(HttpServletRequest request, HttpServletResponse
response)
         throws java.io.IOException, ServletException {

         JspFactory _jspxFactory = null;
         PageContext pageContext = null;
         HttpSession session = null;
         ServletContext application = null;
         ServletConfig config = null;
         JspWriter out = null;
         Object page = this;
         String  _value = null;
         try {

             if (_jspx_inited == false) {
                 synchronized (this) {
                     if (_jspx_inited == false) {
                         _jspx_init();
                         _jspx_inited = true;
                     }
                 }
             }
             _jspxFactory = JspFactory.getDefaultFactory();
             response.setContentType("text/html;charset=ISO-8859-1");
             pageContext = _jspxFactory.getPageContext(this, request,
response,
			"error.jsp", true, 8192, true);

             application = pageContext.getServletContext();
             config = pageContext.getServletConfig();
             session = pageContext.getSession();
             out = pageContext.getOut();

             // HTML // begin [file="/TestScope.jsp";from=(0,86);to=(1,0)]
                 out.write("\r\n");

             // end
             // begin [file="/TestScope.jsp";from=(1,2);to=(6,0)]

                     boolean isJLabel= false;
                     if( request.getParameter("type") !=null &&
request.getParameter("type").equals("JLabel")) {
                         isJLabel=true;
                     }
             // end
             // HTML // begin [file="/TestScope.jsp";from=(6,2);to=(7,0)]
                 out.write("\r\n");

             // end
             // begin [file="/TestScope.jsp";from=(7,2);to=(7,19)]
                  if (isJLabel) {
             // end
             // HTML // begin [file="/TestScope.jsp";from=(7,21);to=(8,4)]
                 out.write("\r\n    ");

             // end
             // begin [file="/TestScope.jsp";from=(8,4);to=(8,69)]
                 javax.swing.JLabel jl = null;
                 boolean _jspx_specialjl  = false;
                  synchronized (request) {
                     jl= (javax.swing.JLabel)

pageContext.getAttribute("jl",PageContext.REQUEST_SCOPE);
                     if ( jl == null ) {
                         _jspx_specialjl = true;
                         try {
                             jl = (javax.swing.JLabel)
java.beans.Beans.instantiate(this.getClass().getClassLoader(),
"javax.swing.JLabel");
                         } catch (Exception exc) {
                              throw new ServletException (" Cannot create
bean of class "+"javax.swing.JLabel", exc);
                         }
                         pageContext.setAttribute("jl", jl,
PageContext.REQUEST_SCOPE);
                     }
                  }
                 if(_jspx_specialjl == true) {
             // end
             // begin [file="/TestScope.jsp";from=(8,4);to=(8,69)]
                 }
             // end
             // HTML // begin [file="/TestScope.jsp";from=(8,69);to=(9,0)]
                 out.write("\r\n");

             // end
             // begin [file="/TestScope.jsp";from=(9,2);to=(9,11)]
                 } else {
             // end
             // HTML // begin [file="/TestScope.jsp";from=(9,13);to=(10,4)]
                 out.write("\r\n    ");

             // end
             // begin [file="/TestScope.jsp";from=(10,4);to=(10,68)]
                 java.util.Vector vec = null;
                 boolean _jspx_specialvec  = false;
                  synchronized (request) {
                     vec= (java.util.Vector)

pageContext.getAttribute("vec",PageContext.REQUEST_SCOPE);
                     if ( vec == null ) {
                         _jspx_specialvec = true;
                         try {
                             vec = (java.util.Vector)
java.beans.Beans.instantiate(this.getClass().getClassLoader(),
"java.util.Vector");
                         } catch (Exception exc) {
                              throw new ServletException (" Cannot create
bean of class "+"java.util.Vector", exc);
                         }
                         pageContext.setAttribute("vec", vec,
PageContext.REQUEST_SCOPE);
                     }
                  }
                 if(_jspx_specialvec == true) {
             // end
             // begin [file="/TestScope.jsp";from=(10,4);to=(10,68)]
                 }
             // end
             // HTML // begin [file="/TestScope.jsp";from=(10,68);to=(11,0)]
                 out.write("\r\n");

             // end
             // begin [file="/TestScope.jsp";from=(11,2);to=(11,5)]
                  }
             // end
             // HTML // begin [file="/TestScope.jsp";from=(11,7);to=(12,0)]
                 out.write("\r\n");

             // end
             // begin [file="/TestScope.jsp";from=(12,2);to=(12,17)]
                  if(isJLabel) {
             // end
             // HTML // begin [file="/TestScope.jsp";from=(12,19);to=(13,4)]
                 out.write("\r\n    ");

             // end
             // HTML // begin [file="/TestScope.jsp";from=(13,36);to=(14,4)]
                 out.write("\r\n    ");

             // end
             // HTML // begin [file="/TestScope.jsp";from=(14,17);to=(15,4)]
                 out.write("\r\n    ");

             // end
             // HTML // begin [file="/TestScope.jsp";from=(15,44);to=(16,4)]
                 out.write("\r\n    ");

             // end
             // begin [file="/TestScope.jsp";from=(16,7);to=(16,29)]
                 out.print( " am in  isJLabel \n");
             // end
             // HTML // begin [file="/TestScope.jsp";from=(16,31);to=(17,4)]
                 out.write("\r\n    ");

             // end
             // begin [file="/TestScope.jsp";from=(17,4);to=(17,49)]

out.print(JspRuntimeLibrary.toString((((javax.swing.JLabel)pageContext.findAttribute("jl")).getText())));
             // end
             // HTML // begin [file="/TestScope.jsp";from=(17,49);to=(18,0)]
                 out.write("\r\n");

             // end
             // begin [file="/TestScope.jsp";from=(18,2);to=(18,11)]
                  } else {
             // end
             // HTML // begin [file="/TestScope.jsp";from=(18,13);to=(19,4)]
                 out.write("\r\n    ");

             // end
             // begin [file="/TestScope.jsp";from=(19,7);to=(19,25)]
                 out.print( " am in  else \n");
             // end
             // HTML // begin [file="/TestScope.jsp";from=(19,27);to=(20,0)]
                 out.write("\r\n");

             // end
             // begin [file="/TestScope.jsp";from=(20,2);to=(20,5)]
                  }
             // end
             // HTML // begin [file="/TestScope.jsp";from=(20,7);to=(21,0)]
                 out.write("\r\n");

             // end

         } catch (Throwable t) {
             if (out != null && out.getBufferSize() != 0)
                 out.clearBuffer();
             if (pageContext != null) pageContext.handlePageException(t);
         } finally {
             if (_jspxFactory != null)
_jspxFactory.releasePageContext(pageContext);
         }
     }
}


I did not include the src from the other jsp (not really needed)



> >From: Ryan Lubke <Ryan.Lubke@Sun.COM>
> >Reply-To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> >To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> >Subject: Re: <jsp:useBean /> Scope Bug in 4.01 !
> >Date: 08 Feb 2002 12:54:43 -0500
> >
> >I agree, the id's are unique.
> >
> >Could you attache the generated source file?
> >I'm unable to reproduce this with a build from the HEAD
> >branch, so I'm curious what the difference (if any) is.
> >
> >
> >
> >On Fri, 2002-02-08 at 12:31, L Rutker wrote:
> > > Back to the basic question where in this code:
> > > <% if (request.getParameter("type")!= null &&
> > >      request.getParameter("type").equals("user")) { %>
> > >      <jsp:useBean id="user" class="com.rutker.UsrData" 
>scope="request"/>
> > > <% } else if(request.getParameter("type")!= null &&
> > >             request.getParameter("type").equals("group")) { %>
> > >      <jsp:useBean id="group" class="com.rutker.GpData" 
>scope="request"/>
> > > <% } %>
> > >
> > >
> > > is there am i "declaring the same ID twice"?
> > >
> > > Thanks
> > > Lou
> > >
> > >
> > > >Hi,
> > > >Can you explain what you mean by:
> > > >
> > > > >     "Duplicate ids found in the same translation unit
> > > > >     shall result in a fatal translation error."
> > > >
> > > >What is duplicate? I am declaring 2 seperate beans based on the
> >condition.
> > > >Neither of them should be visible to the rest of the page. Yet they 
>are
> > > >visible to Tomcat. The
> > > >
> > >
> > > JSP follows the XML syntax rules, which look at the *static* content 
>of
> > > your document at compile time.  As it examines the incoming text, it
> > > discovers that, in fact, you *are* declaring the same ID twice --
> > > conditional execution is a runtime thing, not a compile-time thing.
> > >
> > > Short answer -- "you can't do that".
> > >
> > > >Lou
> > >
> > > Craig
> > >
> > >
> > > >From: "Craig R. McClanahan" <craigmcc@apache.org>
> > > >Reply-To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> > > >To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> > > >Subject: Re: <jsp:useBean /> Scope Bug in 4.01 !
> > > >Date: Fri, 1 Feb 2002 14:41:57 -0800 (PST)
> > > >
> > > >
> > > >
> > > >On Fri, 1 Feb 2002, L Rutker wrote:
> > > >
> > > > > Date: Fri, 01 Feb 2002 12:59:34 -0500
> > > > > From: L Rutker <lrutker@hotmail.com>
> > > > > Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> > > > > To: tomcat-user@jakarta.apache.org
> > > > > Subject: <jsp:useBean /> Scope Bug in 4.01 !
> > > > >
> > > > > Hi,
> > > > > The following is a bug I found using Tomcat 4.01 on NT4
> > > > > The following code:
> > > > >
> > > > > <% if (request.getParameter("type")!= null &&
> > > > > request.getParameter("type").equals("user")) { %>
> > > > >     <jsp:useBean id="user" class="com.rutker.UsrData"
> >scope="request"/>
> > > > > <% } else if(request.getParameter("type")!= null &&
> > > > > request.getParameter("type").equals("group")) { %>
> > > > >     <jsp:useBean id="group" class="com.rutker.GpData"
> >scope="request"/>
> > > > > <% } %>
> > > > >
> > > > > should not be visible to the
> > > > > <jsp:getProperty name="user" property="firstName" />  tag 
farther
> >down
> > > >the
> > > > > page because the useBean tag was declared in the if block, yet the
> > > > > jsp:getProperty tag can see it and works in Tomcat. I noticed the
> >bug
> > > >when I
> > > > > tried the above code on WL 6.1 on Linux and it didnt work. I think
> >that
> > > >WL
> > > > > has the proper implementation.
> > > >
> > > >I don't.  They are violating the JSP Specification if they support
> >this.
> > > >In the JSP 1.3 Specification, Section 4.1 (page 68), you will find 
>the
> > > >following statement:
> > > >
> > > >     "Duplicate ids found in the same translation unit
> > > >     shall result in a fatal translation error."
> > > >
> > > >The fact that you are doing this inside scriptlet conditionals does 
>not
> > > >change the fact that you are using two <jsp:useBean> elements with

>the
> > > >same "id" attribute in the same page.
> > > >
> > > > > Is this the correct mailing list for this post?
> > > >
> > > >The best place to report bugs is in the bug tracking system:
> > > >
> > > >   http://nagoya.apache.org/bugzilla/
> > > >
> > > >
> > > > > Thanks
> > > > > Lou R.
> > > > >
> > > >
> > > >Craig McClanahan


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message