• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Usebean and class/type

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy !

I found an inconsistency in jsp:usebean I can't figure out:

Howcome - the class attribute must be fully-qualified - but the type attribute can "use" an <%@page import ... %> - and thus - only state the class name ??

Rgds, Henri
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe, inadvertently you have used a construct that makes it work.

<%@ page language="java" import="java.util.*" %>
<HTML>
<HEAD>
<TITLE>A JSP USEBEAN APPLICATION</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<jsp:useBean id="col"
scope="session" class="java.util.ArrayList" type="Collection"/>
Class Name = <%= col.getClass().getName() %>
</BODY>
</HTML>

This only works because of the import="java.util.*". Remove that and you will see that it will stop working.

Reason: In Tomcat the equivalent JSP is translated to
...
import java.util.*;
...
col = (Collection) _jspx_page_context.getAttribute("col", PageContext.SESSION_SCOPE);
 
Henrik Krievs
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah - thats my point:

Why can the "type" attribute "see" the import statement - but the "class" attribute don't ?

See my point ?

Rgds, Henrik
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you make the following change to $tomcat-home/conf/web.xml
<servlet>
jsp
...
<init-param>
<param-name>errorOnUseBeanInvalidClassAttribute</param-name>
<param-value>false</param-value>
</init-param>
...
</servlet>

<%@ page language="java" import="java.util.*" %>
...
<jsp:useBean id="col" scope="session" class="ArrayList" type="Collection"/>
Class name = <%= col.getClass().getName() %>

Should work too.

The only problem is that we have now moved a lot of checking from compile time to runtime. Additionally, this url might be helpful.
http://article.gmane.org/gmane.comp.jakarta.tomcat.devel/35870
 
reply
    Bookmark Topic Watch Topic
  • New Topic