I don't remember seeing anything like this already so here is a simple
screen that shows how you might use GNUJSP from within Turbine. To pass
data to the page you would just set it in the session. This is not well
tested because it was just to see how it would be done but works for
simple things. I'm a little concerned that there might be some issues
with the different class loader used by GNUJSP.

To get this to work I had to change Turbine.java and RunData.java to
save the ServletConfiguration. If there is a better way that doesn't
require these changes I'd love to hear it otherwise I've included a
patch.

The screen requires a TurbineResources jsp.servlet attribute set with
the class of the jsp servlet which for GNUJSP is 
jsp.servlet=org.gjt.jsp.JspServlet

You also need to pass all the GNUJSP servlet init parameters to the
Turbine servlet if you want to use jsp. So my zone.properties ends up
with something like this, which is ugly but is taken from the GNUJSP
docs.
servlet.Turbine.initArgs=properties=/infostreet/java/lib/TurbineResources.properties,checkclass=true,pagebase=/infostreet/web,scratchdir=/infostreet/java/servlets/jsp,debug=true,compiler=builtin-javac
-classpath
%classpath%:%scratchdir%:/infostreet/java/lib/servlet-2.0-plus.jar:/infostreet/java/lib/gnujsp10.jar:/infostreet/java/servlets/jsp
-d %scratchdir% -deprecation %source%


package com.infostreet.testapp.screens;

// Java Servlet Classes
import javax.servlet.*;
import javax.servlet.http.*;

// Turbine Modules
import org.apache.turbine.modules.*;

// Turbine Utility Classes
import org.apache.turbine.util.*;

// ECS Classes
import org.apache.ecs.*;

/**
 * A simple demo screen to use JSP from within Turbine.
 *
 * @author <A HREF="mailto:[EMAIL PROTECTED]">Kimbro Staken</A>
 */
public class JspScreen extends Screen
{
    public String getLayout(RunData data)
    {
        return null;
    }

    public ConcreteElement build( RunData data ) throws Exception
    {        
        String servlet = 
            TurbineResources.getInstance().getString("jsp.servlet");
        Class jspClass = Class.forName(servlet);
        Servlet jsp = ( Servlet ) jspClass.newInstance();
            
        jsp.init(data.getServletConfig());
            
        jsp.service(data.req, data.res);

        return null;
    }
}

Index: src/java/Turbine.java
===================================================================
RCS file: /products/cvs/turbine/turbine/src/java/Turbine.java,v
retrieving revision 1.24
diff -u -r1.24 Turbine.java
--- src/java/Turbine.java       1999/12/18 00:56:17     1.24
+++ src/java/Turbine.java       2000/01/12 22:12:01
@@ -95,6 +95,10 @@
         Whether or not init succeeded or not.
     */
     private boolean init = false;
+    /**
+        The configuration object passed to the servlet during init.
+    */
+    ServletConfig config = null;
     
     /**
      * This init method will load the default resources from a
properties file.
@@ -113,6 +117,9 @@
         // setup some defaults from the properties file
         TurbineResources.setPropertiesFileName(props);
 
+        // Hold onto the configuration
+        this.config = config;
+
         init = true;
         log ("Turbine init()!");
     }
@@ -147,7 +154,11 @@
             //get general RunData here... 
             //perform turbine specific initialization below
             data = RunDataFactory.getRunData( req, res );
-            
+
+            // Set the servlet configuration in RunData for use in
loading
+            // other servlets.
+            data.setServletConfig(config);
+                        
             // insist that the client starts a session
             // before access to data is allowed. this is 
             // done by redirecting them to the "Login" page
Index: src/java/org/apache/turbine/util/RunData.java
===================================================================
RCS file:
/products/cvs/turbine/turbine/src/java/org/apache/turbine/util/RunData.java,v
retrieving revision 1.16
diff -u -r1.16 RunData.java
--- src/java/org/apache/turbine/util/RunData.java       2000/01/10
22:45:44    1.16
+++ src/java/org/apache/turbine/util/RunData.java       2000/01/12
22:12:01
@@ -152,7 +152,10 @@
     private String layout = null;
     /** this is where output messages from actions should go */
     private StringElement message = null;
-
+    
+    /** The servlet configuration */
+    private ServletConfig config = null;
+    
     public String stackTrace = null;
     public Exception stackTraceException = null;
 
@@ -390,6 +393,21 @@
     {
         this.user = user;
     }
+    /**
+        Set the Servlet Configuration used during servlet init.
+    */    
+    public void setServletConfig (ServletConfig config)
+    {
+        this.config = config;
+    }
+    /**
+        Get the Servlet Configuration used during servlet init.
+    */    
+    public ServletConfig getServletConfig ()
+    {
+        return this.config;
+    }
+    
     /**
         Whether or not an action has been defined
     */
-- 
Kimbro Staken
Chief Technology Officer
Infostreet Inc.


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to