Servlet Class Converted from UseBean.jspx

This section describes the Servlet class converted from the UseBean.jspx JSP page. The converted Java Servlet class shows how 'useBean', 'setProperty' and 'getProperty' are converted.

If you are interested to see how Tomcat 7 server converts "useBean", "setProperty" and "getProperty" action elements into Java statements before the final execution, open the Servlet class converted from UseBean.jspx:

package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import herong.CacheBean;

public final class UseBean_jspx 
    extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> 
     _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> 
    getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    ...
  }

  public void _jspDestroy() {
  }

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

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(
         this, request, response, null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("<html>");
      out.write("<body>");

      CacheBean b = null;
      b = (CacheBean) _jspx_page_context.getAttribute("b", 
         javax.servlet.jsp.PageContext.PAGE_SCOPE);
      if (b == null){
        b = new CacheBean();
        _jspx_page_context.setAttribute("b", b, 
           javax.servlet.jsp.PageContext.PAGE_SCOPE);
      }

      org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(
         _jspx_page_context.findAttribute("b"), "text", 
         "Hello world!", null, null, false);

      out.write("\n");
      out.write("Property from my JavaBean: \n");

      out.write(
         org.apache.jasper.runtime.JspRuntimeLibrary.toString(
(((CacheBean)_jspx_page_context.findAttribute("b")).getText())));

      out.write("<br/>");
      out.write("\n");
      out.write("Info from my JavaBean: \n");
      out.print(b.getInfo());
      out.write("</body>");
      out.write("</html>");
    } catch (java.lang.Throwable t) {
      ...
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}

Note that:

Last update: 2012.

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

JavaBean Objects and "useBean" Action Elements

 What Is a JavaBean?

 "jsp:useBean" Action Elements

Servlet Class Converted from UseBean.jspx

 Setting and Getting JavaBean's Properties

 Using JavaBean Objects in Scripting Elements

 Using Java Objects as JavaBeans

 getProperty() Error on Tomcat 7

 Refreshing Loaded JavaBean Classes

 Importing Unnamed Package Class Error

 Using JavaBean without Import Element Error

 Creating JavaBean Classes in Named Packages

 "NoClassDefFoundError" Exception

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Outdated Tutorials

 References

 PDF Printing Version