JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»

To help illustrate this translation phase, look at listing 2.9, which shows the servlet produced by the translator for the JSP in listing 2.2. It is clear that the method jspService() (where the service logic of the JSP page is implemented) merely initializes the implicit variables and then executes the page. This execution produces the static HTML via calls to out.write() and executes the scriptlet logic. The scriptlets were added to the file “as is.”

Web server

Listing 2.9 Sample JSP autogenerated servlet

import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.PrintWriter; import java.io.IOException; import java.io.FileInputStream; import java.io.Obj ectInputStream; import java.util.Vector; import org.apache.jasper.runtime.*; import java.beans.*;

import org.apache.jasper.JasperException; public class jspsample1 extends HttpJspBase {

static {


public jspsample1( )    {


private static boolean _jspx_inited = false;

public final void _jspx_init() throws JasperException { }

public void _j spService(HttpServletRequest request,

HttpServletResponse response) throws IOException, ServletException {

JspFactory jspxFactory = null; PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null;

Object page = this;

String value = null; try {

if(_jspx_inited == false) {

_j spx_init();

_jspx_inited = true;


jspxFactory = JspFactory.getDefaultFactory(); response.setContentType(«text/html;charset=8859_1»); pageContext = _j spxFactory.getPageContext(this,



true, 8192, true);

application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut();

out.write(«<HTML>rn<BODY>rn»); C

if(request.getServerName().equals(«localhost»)) {

out.write(«rnYou asked for the server located on your local machine.rn»);

} else {

Скачать в pdf «JSP Tag Libraries»