Essential ATG Dynamo Training - Got atg Certified Relationship Management Developer?
This is not an official ATG site: ATG, Dynamo, Scenario Server and Personalization Server are trademarks or registered trademarks of Art Technology Group
Articles Exercises Resources Links Search

JSP Declarations

What does <%! mean?

What happens if you use the <%! declaration syntax?

<HTML>
<HEAD><TITLE>Test JSP Declarations</TITLE></HEAD>
<BODY>
<%! 
 String name = "Jane";
 Date currentDate = new Date();
 int count=0;
 float value1, value2, value3;
%>
</BODY>
</HTML>

If you are not sure what a JSP tag does simply code it in, view that page and have a look at the java code generated by the page compiler. In dynamo this means look under DYNAMO_HOME\pagebuild. If you placed this code in the default J2ee application that might mean something like this for you:

C:\ATG\Dynamo5.5\home\pagebuild\_c_003a_3\_ATG\_Dynamo5_x5\_J2EE_sDefault\_j2ee_sapps\_j2eeDefault\_web_sapp\_test_xjsp.java

The generated java code is shown below and in this case we can see that the declarations are made at the object scope of the page servlet.

So what? Well:

  • Firstly this is probably not to be done unless you have a very important reason, since many threads can be in your servlet at the same time, you may have more work to do synchronizing thread access to these variables.
  • These variable will hang around for the lifetime of the jsp servlet; for one or more requests
  • They can be accessed from other methods you might declare (using the same <%! syntax)
  • You might want to initialize some of them in your page code and/or init() method
  • currentDate when the page is loaded is not necessarily the current date when the page is viewed

In this case this is the java code we get:

package _c_003a_3._ATG._Dynamo5_x5._J2EE_sDefault._j2ee_sapps._j2eeDefault._web_sapp._UsingJSPTechnology._test;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import atg.nucleus.*;
import atg.naming.*;
import atg.service.filecache.*;
import atg.servlet.*;
import atg.droplet.*;
import atg.servlet.pagecompile.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import atg.servlet.jsp.*;

public class _pizzaPlaces_xjsp
extends atg.servlet.jsp.DynamoJspPageServlet implements AttrCompiledServlet {
  public String getFileCacheAttributeName() {
    return "__002fUsingJSPTechnology_002ftest_002fpizzaPlaces_xjsp";
  }
  
  public static final long SOURCE_MODIFIED_TIME = 1001976476000L;
 
  String name = "Jane";
  Date currentDate = new Date();
  int count=0;
  float value1, value2, value3;
  
  public static final String[] INCLUDED_SOURCE_URIS = null;
  public static final long[] INCLUDED_SOURCE_MODIFIED_TIMES = null;
  public static String[] _jspDynGetSourceURIs() {
    return INCLUDED_SOURCE_URIS;
  }
  
  public static String _jspGetEncoding() {
    return null;
  }
  

  //-------------------------------
  {
  
    DropletImports _imports = new DropletImports();
    this. setParameter("_imports", _imports);
  }
  
  //-------------- The _jspService method
  public void _jspService (DynamoHttpServletRequest request,
                       DynamoHttpServletResponse response)
      throws ServletException, IOException
  {
    ByteFileData __fileData = null;
    try {
      __fileData = (ByteFileData)       request.getAttribute(getFileCacheAttributeName())      ;
      JspFactory _jspFactory = DynamoJspFactory.getDynamoJspFactory();
      DynamoJspPageContext pageContext = (DynamoJspPageContext)_jspFactory.getPageContext(
        this, request, response, 
        null,true, JspWriter.DEFAULT_BUFFER, true);
        ServletConfig config = getServletConfig();
        ServletContext application = config.getServletContext();
        HttpSession session = pageContext.getSession();
        Object page = this;
      
      ByteBufferedBodyContent out = (ByteBufferedBodyContent)pageContext.getOut();
      
      int _jspTempReturn;
      
      try {

        FormTag _form = (FormTag) request.getObjectParameter(ServletUtil.FORM_NAME);
        DropletImports _imports = (DropletImports) request.getObjectParameter(ServletUtil.IMPORTS_NAME);
        /*** lines: 1-4 */
        __fileData.writeBytes (0, 67, out);
        /*** lines: 9-11 */
        __fileData.writeBytes (179, 20, out);
      } catch (Exception e) {
        if (!(e instanceof EndOfPageException)) {
          // out.clear();
          out.clearBuffer();
          pageContext.handlePageException(e);
        }
      }
      finally {
        pageContext.cleanupPoppedBodyContent();
        out.close();
        _jspFactory.releasePageContext(pageContext);
      }
    }
    finally {
      if (__fileData != null) __fileData.close();
    }
  }
}

jsp:include flush="true"

When you specify a dynamic jsp:include you must specify the flush="true", that's just the way it is, it's reserved for future use.

<jsp:include page="pizzaPlacesList.jsp" flush="true">
  <jsp:param name="featured" value="Joe's on Polk, Oakland"></jsp:param>
</jsp:include>


Technical Training Advertise your Training Programs for Free! Los Angeles Web Design Shopping Cart Software  Form a Corporation