Java Web黑马程序员 听课笔记

来源:互联网 发布:公知污名化 编辑:程序博客网 时间:2024/05/21 00:19

一、Web后台架构

二、HTTP请求

请求头

Accept: 客户机支持的数据类型

Accept-Charset: 客户机采用的编码

Accept-Encoding: 客户机支持的数据压缩格式

Accept-Language: 客户机的语言环境

Host: 想访问的主机名

If-Modified-Since: 告诉服务器资源的缓存时间

Referer: 告诉服务器,我是从哪个资源访问服务器的

User-Agent: 告诉服务器客户机的软件环境

Cookie:

Connection: close/Keep-Alive

Date: 当前时间

 

三、HTTP响应

响应头

Location: 配合302状态码使用,用于告诉客户端找谁

Server: 服务器的类型

Content-Encoding: 告诉浏览器数据的压缩格式

Content-Length: 回送数据的长度

Content-Type: 回送数据的类型

Last-Modified: 告诉浏览器当前资源缓存时间

Refresh: 告诉浏览器多长时间刷新一次

Content-Disposition: 以下载方式打开数据

Transfer-Encoding: 告诉浏览器数据的传送格式

ETag: 缓存相关的头(比较数据在服务器是否改变,如果未改变,则令浏览器直接取缓存。可以做到实时更新)

Expires: 告诉浏览器把回送的资源缓存多长时间。-1或0表示不缓存。

Cache-Control: no-cache

Pragma: no-cache

服务器通过以上两个头,控制浏览器不要缓存数据。

四、线程安全性问题

解决办法:

1、synchronized

2、implementsSingleThreadModel

五、建议配置的初始化参数有

1、字符集类型UTF-8

2、数据库名称

3、数据库用户名密码

4、需要载入的配置文件名

六、读取Properties:

InputStream in =this.getServletContext().getResourceAsStream();

Properties props = new Properties();

props.load(in);

String url = prop.getProperty("url");

String username =prop.getProperty("username");

String password =prop.getProperty("password");

七、JSP指令

1.page指令

2.include指令

3.taglib指令

jsp九大隐式对象

request

response

session

application

config

page

out

exception

pageContext

八、自定义标签的作用:替代jsp中的所有Java代码。

使用标签输出客户机IP:

1.编写一个实现tag接口的Java类

public class ViewTag extends TagSupport {

 

 

@Override

public int doStartTag() throws JspException{

 

HttpServletRequest request =(HttpServletRequest) this.pageContext.getRequest();

JspWriter out = this.pageContext.getOut();

 

String ip = request.getRemoteAddr();

try {

out.print(ip);

} catch (IOException e) {

throw new RuntimeException(e);

}

 

return super.doStartTag();

 

}

 

}

2.在tld文件中对标签处理器类进行描述(tld文件的位置:WEB-INF下)

<?xml version="1.0"encoding="UTF-8" ?>

 

 

<taglibxmlns="http://java.sun.com/xml/ns/j2ee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"

version="2.0">

<description>A tag library exercisingSimpleTag handlers.</description>

<tlib-version>1.0</tlib-version>

<short-name>wjg</short-name>

<uri>http://www.wjg.com</uri>

 

<tag>

<name>viewIP</name>

<tag-class>cn.wjg.web.tag.ViewTag</tag-class>

<body-content>empty</body-content>

</tag>

</taglib>

3.在jsp页面中导入并使用自定义标签

导入:

<%@tagliburi="http://www.wjg.com" prefix="wjg" %>

使用:

您的ip是:<wjg:viewIP/>

九、JSTL标签库

1.核心标签库

2.国际化标签

3.数据库标签(不符合MVC模式)

4.XML标签(不符合MVC模式)

5.JSTL函数(EL函数)

十、11大隐式对象

pageContext

pageScope:表示一个保存了page域所有Attribute的Map集合

requestScope:表示一个保存了request域所有Attribute的Map集合

sessionScope:表示一个保存了session域所有Attribute的Map集合

applicationScope:表示一个保存了application域所有Attribute的Map集合

param:表示一个保存了所有请求参数的Map集合

paramValues:表示一个保存了所有请求参数的Map集合,它对于一个请求,返回的是String[]对象

header:表示一个保存了所有http请求头字段的Map对象

headerValues:同paramValues

cookie:表示一个保存了所有cookie的Map集合

initParam:表示一个保存了所有web应用初始化参数的Map对象(在web.xml中用<context-param>设置)


0 0
原创粉丝点击