一.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. 数据类型 varchar 和 uniqueidentifier 在 add 运算符中不兼容

    select '<a href="/'+a.id +'" title="'+ a.title +'">'+a.Title+'</a>' ...

  2. Mysql 索引之B+tree

    InnoDB使用的是聚簇索引,将主键组织到一棵B+树中,而行数据就储存在叶子节点上,若使用"where id = 14"这样的条件查找主键,则按照B+树的检索算法即可查找到对应的叶 ...

  3. Notepad++对比文件

    Notepad++怎么对比文件,安装文件对比插件Compare pluginhttps://blog.csdn.net/qq_31772441/article/details/80306265 可以只 ...

  4. jieba库及词频统计

    import jieba txt = open("C:\\Users\\Administrator\\Desktop\\流浪地球.txt", "r", enco ...

  5. Venom- Eminem

    I got a song filled with shit for the strong willed. 我写了一首充满戾气的歌献给意志坚强的人. When the world give you a ...

  6. 小账本APP——软件项目风险管理及解决办法案例

    小账本APP——软件项目风险管理及解决办法案例 摘要 软件项目风险是指在软件开发过程中遇到的预算和进度等方面的问题以及这些问题对软件项目的影响.软件项目风险会影响项目计划的实现,如果项目风险变成现实, ...

  7. 【转】RTP学习笔记

    转自:https://www.cnblogs.com/yoyotl/p/5650101.html 一.定义 实时传输协议(Real- time Transport Protocol,RTP)是在Int ...

  8. .NET Core WEB API中接口参数的模型绑定的理解

    在.NET Core WEB API中参数的模型绑定方式有以下表格中的几种: 微软官方文档说明地址:https://docs.microsoft.com/zh-cn/aspnet/core/web-a ...

  9. 虚函数 error LNK2001: 无法解析的外部符号 "public: virtual void __cdecl

    在虚函数后面加一对大括号 #ifndef CAFFE_CONV_DW_LAYER_HPP_ #define CAFFE_CONV_DW_LAYER_HPP_ #include <vector&g ...

  10. django+nginx+gunicorn+pipenv微信小程序实践笔记

    一.我采用pipenv来管理虚拟环境,在本地新建虚拟环境: mkdir wxProject #进入环境目录,创建虚拟环境 pipenv install #激活虚拟环境 pipenv shell #然后 ...