一.JSP的本质

其本质是Servlet,web应用中的每个jsp页面都会由servlet容器生成对应的servlet。

在tomcat中,jsp生成的servlet在work文件夹下:

原jsp文件:

对应的servlet

show.jsp

<%-- 编译指令--%>
<%@page contentType="text/html;charset=UTF-8" language="java" errorPage="error.jsp"%>
<%@page info="this is a jsp page"%>
<html>
<head>
<title>
欢迎
</title>
</head>
<%-- jsp声明变量和方法--%>
<%!
private int count;
private int num;
public String print(){
return "hello";
}
%>
<body> <%-- jsp注释,不会出现在浏览器的源代码中。只在服务端。--%>
<!--html注释-->
你访问!
<%out.print(new java.util.Date());%>
<%for(int i=0;i<5;i++){
out.print("<font size='"+i+"'>" );%>
hello world</font> <%}%> <%-- 变量和方法使用--%>
<%out.print(count++);
%>
<%out.print(print());%>
<%-- JSP表达式--%>
<%=num++%>
<%=getServletInfo()%> <table border="1">
<%-- jsp脚本--%>
<%for(int j=0;j<8;j++){%>
<%!private int n;%>
<tr><td>n++</td></tr> <%}%> <%-- 这里出现异常,跳转向error.jsp--%>
<%!int m=7;
int p=4;
%>
<%=m/p%>
</table>
</body>
</html>

show_jsp.java

package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*; public final class show_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
//jsp中编译指令page的info属性
public String getServletInfo() {
return "this is a jsp page";
} //jsp中声明的变量和方法
private int count;
private int num;
public String print(){
return "hello";
} private int n;
int m=7;
int p=4; private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory(); private static java.util.List _jspx_dependants; private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.AnnotationProcessor _jsp_annotationprocessor; public Object getDependants() {
return _jspx_dependants;
}
//初始化JSP/servlet的方法
public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
}
//销毁JSP/servlet之前的方法
public void _jspDestroy() {
}
//对用户请求生成响应的方法
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException { PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null; try {
response.setContentType("text/html;charset=UTF-8");
pageContext = _jspxFactory.getPageContext(this, request, response,
"error.jsp", true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out; out.write("\r\n");
out.write("\r\n");
out.write("<html>\r\n");
out.write("<head><title>\r\n");
out.write("欢迎\r\n");
out.write("\r\n");
out.write("</title>\r\n");
out.write("</head>\r\n");
out.write("\r\n");
out.write("\r\n");
out.write("<body>\r\n");
out.write("\r\n");
out.write("\r\n");
out.write("<!--html注释-->\r\n");
out.write("你访问!\r\n");
out.print(new java.util.Date());
out.write('\r');
out.write('\n');
for(int i=0;i<5;i++){
out.print("<font size='"+i+"'>" );
out.write("\r\n");
out.write("\thello world</font>\r\n");
out.write("\t\r\n");
out.write("\t\r\n");
}
out.write("\r\n");
out.write("\r\n");
out.write("\r\n");
out.print(count++); out.write('\r');
out.write('\n');
out.print(print());
out.write('\r');
out.write('\n');
out.print(num++);
out.write("\r\n");
out.write("<table border=\"1\">\r\n");
for(int j=0;j<8;j++){
out.write('\r');
out.write('\n');
out.write("\r\n");
out.write("<tr><td>n++</td></tr>\r\n");
out.write("\t\r\n");
}
out.write('\r');
out.write('\n');
out.print(getServletInfo());
out.write('\r');
out.write('\n');
out.write('\r');
out.write('\n');
out.print(m/p);
out.write("\r\n");
out.write("</table>\r\n");
out.write("</body>\r\n");
out.write("</html>\r\n");
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}

二.JSP的工作原理

JSP学习(1)---JSP基本原理的更多相关文章

  1. jsp学习:jsp学习阶段性总结2019.9.21

    Jsp学习 jsp语法格式: 脚本程序:<% 代码片段 %> jsp声明:<%! declaration; [ declaration; ]+ ... %> 表达式:<% ...

  2. jsp学习---使用jsp和JavaBean实现超简单网页计算器

    一.需求 如题,用jsp实现一个超简单的网页计算器. 二.实现 1.效果图 1)初始界面: 2)随便输入两个数进行相乘: 3)当除数为零时提示报错: 2.代码 Calculator.java pack ...

  3. 重温JSP学习笔记--JSP动作标签

    上一篇笔记写的是jsp的三个指令九个内置对象,这篇随笔开始写jsp的动作标签,动作标签是由服务器(Tomcat)来解释执行,与java代码一样,都是在服务器端执行的,jsp动作标签有十几多个,这里只写 ...

  4. [jsp学习笔记] jsp过滤器

  5. [jsp学习笔记] jsp基础知识 数据初始化、同步

  6. JSP学习笔记

    JSP学习笔记 Jsp网页主要分为Elements与Template Data两部分. Template Data:JSP Container不处理的部分,例如HTML内容 Elements:必须经由 ...

  7. JSP学习(2)

    JSP学习(2) JSP简介 Java Server Page,其根本是一个简单Servlet设计. 常用的动态网站开发技术 JSP:安全性高,适合开发大型的,企业级或分布式的Web应用程序. Asp ...

  8. JSP学习(3)

    JSP学习(3) JSP内置对象 Web容器创建的一组对象,不使用new关键字就可以使用的内置对象 用户服务器请求 缓冲区:Buffer,就是内存的一块区域,用来保存临时数据. get与post的区别 ...

  9. JSP 学习笔记1

    JSP 学习笔记   JSP是Servlet的一种特殊形式,每个JSP页面就是一个Servlet实例--JSP页面有系统编译成Servlet,Servlet再负责响应用户请求. 1.JSP注释 < ...

  10. JSP学习网站

    JSP学习网站 http://www.yiibai.com/jstl/ http://www.w3cschool.cc/jsp/jsp-jstl.html

随机推荐

  1. SQL Server同一表不同列数据同步

    直接上脚本 update table set a=b where a=xxx table==表名称 a==需要同步的列 b==数据源列,就是a列要的数据是b列的数据 where 条件.不加where则 ...

  2. UNDO -- Concept

     Undo data Records of the actions of transactions, primarily before they are committed. The database ...

  3. hive中控制文件生产个数

    在有些时候,想要控制hql执行的mapper,reducer个数,reducer设置过少,会导致每个reducer要处理的数据过多,这样可能会导致OOM异常,如果reducer设置过多,则会导致产生很 ...

  4. 关于spark写入文件至文件系统并制定文件名之自定义outputFormat

    引言: spark项目中通常我们需要将我们处理之后数据保存到文件中,比如将处理之后的RDD保存到hdfs上指定的目录中,亦或是保存在本地 spark保存文件: 1.rdd.saveAsTextFile ...

  5. Linux 细节(杂)

    1.所有上传至linux服务器的文件都是英文,避免中文出现乱码导致一些非预期错误,难以查找. 2.删除较危险,linux没有回收站,慎用 rm -rf 3.vi/vim学习地址:http://www. ...

  6. Linux压缩与解压缩文件

    1 将tgz文件解压到指定目录. tar zxvf test.tgz -C 指定目录 比如:将 test.tgz 解压到 /home目录:tar zxvf test.tgz -C /home 2 将指 ...

  7. 安卓开发创建活动,布局,添加按钮,she使用Toast,设菜单,使菜单相关联等操作

    ---恢复内容开始--- 创建一个新活动在app/src/main/java/com.example.activitytest ,然后右击com.example.activitytest包→New→A ...

  8. 【Java】【10】后台处理Emoji表情

    问题:存到数据库的emoji表情,取出来后,在前端显示为乱码 环境:SpringBoot + Oracle(MySQL据说是支持表情的) 解决方案: 引入emoji相关的jar包,使用很方便,不过表情 ...

  9. 【期望dp】绵羊跳弹簧

    [期望dp] 绵羊跳弹簧 >>>>题目 [题目] T 组数据.对于每一组数据,有n+1 个格子从0 到n 标号,绵羊从0 号结点开始,每次若在 x 位置掷骰子,令掷出的数为nu ...

  10. 【javascript】数据类型中的一些小知识点

    1. undefined 和 null undefined是一个变量而不是一个关键字,所以可以被重新赋值.为了避免歧义,一般推荐用void 0 来获取undefined: null是一个关键字,所以可 ...