I think that the processRequest did provide some benefits. Although it
really left me wanting a little bit more.
The main benefit of processRequest as I see it, is the beginning of
some structure and definition of what a JSP bean is. Unfortunately, it
seems that some are very against any kind of JSP specific bean
interface. Possibly for fear that all beans used in JSP would then need
to be JSP specific. I agree that any type of bean should be able to be
used inside of JSP. I also think that there is much to gain from
defining a JSP specific bean interface. We could call beans that
implement this interface Pagelets.
The key benefits of Pagelets would be:
* Having a non-intrusive interface that JSP beans can optionally
implement.
* Ability to create Servlet and JSP aware beans.
* Beans that can cleanup after itself.
* Pagelets would be thread-safe since a Pagelet can only be
associated with one page at a time.
* A place to put processRequest
Here is what the Pagelet interface can look like:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
package javax.servlet.jsp;
public interface Pagelet {
/**
* Initializes the pagelet. Pagelets have a lifespan of page.
* destroy() is called at the end of _jspService.
*/
public void init(PageContext pageContext);
/**
* <p>This method gives the pagelet an opportunity
* to clean up any resources that are being held (for example,
* jdbc connections)
*/
public void destroy();
/**
* Backwards compatibility, init(PageContext pageContext) would
* replace it.
*
* @deprecated
*/
public void processRequest(HttpServletRequest request);
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
Here are Pagelets in action:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
<jsp:useBean id="jdbcConnection" scope="page"
class="pagelets.JdbcConnection"/>
<jsp:useBean id="allUsers" scope="page" class="pagelets.AllUsers"/>
<jsp:useBean id="allGroups" scope="page" class="pagelets.AllGroups"/>
<html>
All Users:<br>
<ol>
<%
String[] users = allUsers.getUsers();
for (int i = 0; i < users.length; i++) {
%>
<li> <%= users[i] %>
<%
}
%>
</ol>
<p>
All Groups:<br>
<ol>
<%
String[] groups = allGroups.getGroups();
for (int i = 0; i < groups.length; i++) {
%>
<li> <%= groups[i] %>
<%
}
%>
</ol>
</html>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
How Pagelets benefit us in this example would be automatic clean up of
the JDBC connection and the ability to invisibly share the connection.
The Pagelet jdbcConnection would have its destroy() method called at
the end of _jspService and would then close the connection. Meanwhile
both allUsers and allGroups could have used the database connection
that jdbcConnection created and made available through the
request.setAttribute().
I think Pagelets can consolidate and provide some features that people
have been asking for on the JSP list. One being processRequest
functionality and another being Thread-Safe beans, and my personal
favorite automatic bean cleanup.
-James Klicman
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".