JSP ————> servlet

我的第1个Java Web应用程序——index.jsp

我的第2个Java Web应用程序——welcome-file

我的第3个Java Web应用程序——conf/server.xml

我的第4个Java Web应用程序——jsp page

我的第5个Java Web应用程序——jsp 脚本

我的第6个Java Web应用程序——jsp 声明

我的第7个Java Web应用程序——JSP 表达式

我的第8个Java Web应用程序——JSP页面生命周期

我的第9个Java Web应用程序——我的乘法口诀表!

1

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<h1>???????</h1>
</body>
</html>
<?xml version="1.0" encoding="ISO-8859-1" ?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
</web-app>

2

<?xml version="1.0" encoding="ISO-8859-1" ?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
</web-app>

3

4

jsp=java server page

<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8" %>

<html>
<body>
<h1 align="center">啤酒推荐</h1>
<p>
<%
List styles = (List)request.getAttribute("styles");
Iterator it = styles.iterator();
while (it.hasNext()) {
out.print("<br>try: " + it.next());
}
%>
</body>
</html>

5

<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8" %>

<html>
<body>
<h1 align="center">啤酒推荐</h1>
<p>
<%
List styles = (List)request.getAttribute("styles");
Iterator it = styles.iterator();
while (it.hasNext()) {
out.print("<br>try: " + it.next());
}
%>
<%
out.print("<br /><br />今天天气貌似不错!");
// out是一个内置的对象!
%>

</body>
</html>

6

两种声明方式的差异。参考:http://www.cnblogs.com/zengmiaogen/archive/2012/04/15/2450414.html

我们既可以在<%%>中声明变量,也可以在<%!%>中声明变量,

那么,这两种声明方式有什么区别呢?事实上,<%!%>相当于类的实例域,而<%%>相当于方法体。

// TO-DO

7

<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8" %>

<html>
<body>
<p>this is a simple test</p>
<%!
String words = "this is a simple test.";
int sum(int x, int y) {
return x + y;
}
%>
<p>words=<%=words%></p>
<p>3+4=<%=sum(3,4)%></p>
</body>
</html>

8

当我们访问jsp页面的时候,jsp引擎(web容器)首先判断是否是第一次请求...

这个时候我就想,要是可以直接看到它编译出来的字节码就好了,那么到哪里查看呢?——答案是在tomcat的work目录下,不仅有字节码,还有源代码,我们查看一下上一节的代码。

/*
* Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/7.0.77
* Generated at: 2017-06-09 10:07:20 UTC
* Note: The last modified time of this file was set to
* the last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp; import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*; public final class test_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent { String words = "this is a simple test.";
int sum(int x, int y) {
return x + y;
} 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 volatile javax.el.ExpressionFactory _el_expressionfactory;
private volatile org.apache.tomcat.InstanceManager _jsp_instancemanager; public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
return _jspx_dependants;
} public javax.el.ExpressionFactory _jsp_getExpressionFactory() {
if (_el_expressionfactory == null) {
synchronized (this) {
if (_el_expressionfactory == null) {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
}
}
}
return _el_expressionfactory;
} public org.apache.tomcat.InstanceManager _jsp_getInstanceManager() {
if (_jsp_instancemanager == null) {
synchronized (this) {
if (_jsp_instancemanager == null) {
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
}
}
}
return _jsp_instancemanager;
} 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("\r\n");
out.write("\r\n");
out.write("<html>\r\n");
out.write(" <body>\r\n");
out.write(" \t<p>this is a simple test</p>\r\n");
out.write(" \t");
out.write("\r\n");
out.write(" \t<p>words=");
out.print(words);
out.write("</p>\r\n");
out.write(" \t<p>3+4=");
out.print(sum(3,4));
out.write("</p>\r\n");
out.write(" </body>\r\n");
out.write("</html>");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try {
if (response.isCommitted()) {
out.flush();
} else {
out.clearBuffer();
}
} catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
else throw new ServletException(t);
}
} finally
{
_jspxFactory.releasePageContext(_jspx_page_context);
}
}

}

9

<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8" %>

<html>
<body>
<p>这是我的乘法口诀表!</p> <%
for (int i = 1; i <= 9; ++i) {
for (int j = 1; j <= i; ++j) {
out.print(i + " * " + j + " = " + i*j + " ");
}
out.print("<br />");
}
%> </body>
</html>

看完视频后修改了一下,&nbsp;是空格占位符

<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8" %>

<html>
<body>
<p>这是我的乘法口诀表!</p> <%!
void printTable() {
for (int i = 1; i <= 9; ++i) {
for (int j = 1; j <= i; ++j) {
out.print(i + " * " + j + " = " + i*j + "&nbsp;&nbsp;&nbsp;&nbsp;");
}
out.print("<br />");
}
}
%> <%
printTable();
%> </body>
</html>

10什么是内置对象

11 jsp有哪些内置对象

12 jsp内置对象的官方文档

JSP笔记01——尝试的更多相关文章

  1. SaToken学习笔记-01

    SaToken学习笔记-01 SaToken版本为1.18 如果有排版方面的错误,请查看:传送门 springboot集成 根据官网步骤maven导入依赖 <dependency> < ...

  2. Redis 笔记 01:入门篇

    Redis 笔记 01:入门篇 ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ...

  3. 软件测试之loadrunner学习笔记-01事务

    loadrunner学习笔记-01事务<转载至网络> 事务又称为Transaction,事务是一个点为了衡量某个action的性能,需要在开始和结束位置插入一个范围,定义这样一个事务. 作 ...

  4. 《30天自制操作系统》笔记(01)——hello bitzhuwei’s OS!

    <30天自制操作系统>笔记(01)——hello bitzhuwei's OS! 最初的OS代码 ; hello-os ; TAB=4 ORG 0x7c00 ; 指明程序的装载地址 ; 以 ...

  5. 《The Linux Command Line》 读书笔记01 基本命令介绍

    <The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...

  6. PHP 学习笔记 01

    例子: 为什么要学PHP 主观原因: 前段时间在学校处理了毕业的一些事情,回到上海后开始了找工作的旅程.意向工作是WPF开发或者ASP.NET 作为后端的WEB开发. 陆陆续续一直在面试,其中有一家公 ...

  7. 【技能大赛笔记01】Zigbee点对点按键控制程序开发

    [技能大赛笔记01]Zigbee点对点按键控制程序开发 --2017年"物联网物联网技术应用与维护"任务五题1(中职组) 1.题目要求 2.工程文件 在比赛中,提供了一个基于Bas ...

  8. JS自学笔记01

    JS自学笔记01 1.开发工具 webstorm 2.js(javascript) 是一门脚本.解释性.动态类型.基于对象的语言 含三个部分: ECMAScript标准–java基本语法 DOM(Do ...

  9. 《30天自制操作系统》笔记(01)——hello bitzhuwei’s OS!【转】

    转自:http://www.cnblogs.com/bitzhuwei/p/OS-in-30-days-01-hello-bitzhuwei-OS.html 阅读目录(Content) 最初的OS代码 ...

随机推荐

  1. 集合映射Set(使用xml文件)

    如果持久类具有Set对象,可以在映射文件中使用set元素映射Set集合. set元素不需要索引元素. List和Set之间的区别是: Set只存储唯一的值. 我们来看看我们如何在映射文件中实现集合: ...

  2. Spring MVC配置静态资源和资源包教程

    1- 介绍 这篇教程文章是基于: Spring 4 MVC 2- 创建一个项目 File/New/Other.. 输入: Group ID: com.yiibai Artifact ID: Sprin ...

  3. 关于JAVA编译时找不到自定义包的问题

    这两天照网上的教程,学习JSP/SERVLET/JAVABEAN,写了几个JAVA文件,目录放在TOMCAT的WEBAPPS下面,通过javac编译时,老提示找不到指定的包: 下图是我的目录路径: 通 ...

  4. C#二进制序列化和反序列化

    public class WRSerializable { public static void SerializeToFile<T>(T _description, string _fi ...

  5. Ubuntu安装特定版本安装包

    Ubuntu安装特定版本安装包可以用aptitude,aptitude是apt-get的高级版,使用起来更强大. aptitude install package=version 比如我要安装2.6. ...

  6. 用ElasticSearch搭建自己的搜索和分析引擎【转自腾讯Wetest】

    本文大概地介绍了ES的原理,以及Wetest在使用ES中的一些经验总结.因为ES本身涉及的功能和知识点非常广泛,所以这里重点挑出了实际项目中可能会用到,也可能会踩坑的一些关键点进行了阐述. 一 重要概 ...

  7. 系统时钟和UART的设置

    系统时钟: 在开发版上,不同的器件运行在不同的时钟频率上,如CPU可能运行在400Mhz的频率上.SDRAM.DM9000等内存存储运行在100Mhz~133MHz上. 串口i2c等运行在50Mhz上 ...

  8. 在Windows 7 (SP1)上安装Visual Studio 2015

    背景说明:最近重装了Windows 7 系统,那就顺手装个Visual Studio 2015吧,没想到一案装就报错(具体没截图了).只有Windows8 或是Windows 10才能装 2015?答 ...

  9. [Spring Data MongoDB]学习笔记--_id和类型映射

    _id字段的映射: MongoDB要求所有的document都要有一个_id的字段. 如果我们在使用中没有传入_id字段,它会自己创建一个ObjectId. { , "accounts&qu ...

  10. 【网络编程】之十三、ping程序实现

    使用原始套接字:SOCK_RAW 需要ICMP 代码如下: #include<iostream> #include<WinSock2.h> using namespace st ...