JSP技术实现动态页面到静态页面的方案

发表于:2010-12-30 10:17

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:51Testing软件测试网采编

#
java
#
JAVA
#
Java
#
JSP

  对于JSP技术实现动态页面到静态页面的方案,我们从三个步骤来说明:

  JSP技术实现动态页面到静态页面的方案第一:

  为了能深入浅出的理解这个框架的由来,我们首先来了解一下JSP解析器将我们写的JSP代码转换成的JAVA文件的内容。

  下面是一个JSP文件test.jsp

  • ﹤%@ page language=java  contentType=text/html;charset=GB2312 %﹥  
  • ﹤%  
  • out.write(﹤!--文件开始--﹥);  
  • %﹥  
  • ﹤html﹥  
  • ﹤head﹥  
  • ﹤body﹥  
  • ﹤%=输出%﹥  
  • ﹤/body﹥  
  • ﹤/head﹥  
  • ﹤/html﹥  
  •   经过Tomcat转换出的Java文件test$jsp.java内容如下:

  • package org.apache.jsp;  
  • import javax.servlet.*;  
  • import javax.servlet.http.*;  
  • import javax.servlet.jsp.*;  
  • import org.apache.jasper.runtime.*;  
  • public class test$jsp extends HttpJspBase {  
  •  static {  
  •  }  
  •  public testOutRedir$jsp( ) {  
  •  }  
  •  private static boolean _jspx_inited = false;  
  •  public final void _jspx_init() throws org.apache.jasper.runtime.JspException {  
  •     }  
  •    public void _jspService(HttpServletRequest request, HttpServletResponse  response)  
  •         throws java.io.IOException, ServletException {  
  •  JspFactory _jspxFactory = null;  
  •  PageContext pageContext = null;  
  •  HttpSession session = null;  
  •         ServletContext application = null;  
  •         ServletConfig config = null;  
  •        JspWriter outnull;  
  •         Object page = this;  
  •         String  _value = null;  
  •         try {  
  •             if (_jspx_inited == false) {  
  •                 synchronized (this) {  
  •                     if (_jspx_inited == false) {  
  •                         _jspx_init();  
  •                        _jspx_inited = true;  
  •                     }  
  •                 }  
  •             }  
  •             _jspxFactory = JspFactory.getDefaultFactory();  
  •             response.setContentType(text/html;charset=GB2312);  
  •             pageContext = _jspxFactory.getPageContext(this, request, response,  
  •                           , true, 8192, true);  
  •             application = pageContext.getServletContext();  
  •             config = pageContext.getServletConfig();  
  •             session = pageContext.getSession();  
  •            outpageContext.getOut();  
  •                //为了节省篇幅,我删除了解释器添加的注释  
  •                out.write(\r\n);  
  •   //上一句是由于  
  •  ﹤%@ page language=java  contentType=text/html;charset=GB2312 %﹥后面的换行产生的  
  •                out.write(﹤!--文件开始--﹥);  
  •                out.write(\r\n﹤html﹥\r\n﹤head﹥\r\n﹤body﹥\r\n);  
  •                out.print(输出);  
  •                out.write(\r\n﹤/body﹥\r\n﹤/head﹥\r\n﹤/html﹥\r\n);  
  •         } catch (Throwable t) {  
  •             if (out!= null &&out.getBufferSize() != 0)  
  •                out.clearBuffer();  
  •             if (pageContext != null) pageContext.handlePageException(t);  
  •         } finally {  
  •             if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);  
  •         }  
  •     }  
  • }  
  • 31/3123>
    《2023软件测试行业现状调查报告》独家发布~

    关注51Testing

    联系我们

    快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

    法律顾问:上海兰迪律师事务所 项棋律师
    版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
    投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

    沪ICP备05003035号

    沪公网安备 31010102002173号