NOTE:Jsp and Servlet

2007-4-13
____________________________________________________________________________________________
1.web服务器用于处理HTTP请求,而应用服务器则用于提供和web应用相关的服务
2.Servlet是利用HttpServletRequest类的getParameter()方法来取得网页传来的数据.不过
  数据通过HTTP协议传输时会被转码,因此在润滑剂地,必须再做转码的工作,才能正确地接收到
数据.

2007-4-16
____________________________________________________________________________________________
1.关于response.sendRedirect(String str)

2.关于response.setHeader(String str1,String str2)

3.session对象不像其他的隐含对象,可以在任何的JSP网页中使用,如果在JSP网页中,
page指令的属性session设为false时,使session对象就会产生编译错误.

4.关于pageContext
默认情况下,pageContext的作用域是其所在网页,但是它的功能远不止此.
一方面它能够读取和设置四种作用域不同的对象的属性(通过在它的setAttribute()和getAtrribute()
方法的中添加一个int型参数,来指定其读取和设置的属性所处的域)
另一方面它还具有取得当前页面中session/request/response/application隐含对象的能力!

2007-4-17
____________________________________________________________________________________________
1.关于http的请求与响应的

http作用一种非常简单的通信模型:即请求与响应模式.
客户端需要获取资源或申请服务时,它会向服务器发送一个请求,然后服务器接受请求,给出一个响应.
在http中请求与响应都有固定的形式:

对于一个请求它主要包含一个请求行和一个请求头标和一个请求体.如:

GET /index.html HTTP/1.1 /*请求行*/

Host: www.gefionsoftware.com /*请求头标*/
User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv: 1.0.2)
Accept: image/gif, image/jpeg, image/pjpeg, image/png, */*
Accept-Language : en
Accept-Charset : iso-8859-1,*,utf-8

对于一个响应,它主要包含一个响应行/一个响应头标/和一个可选的响应体(例如一段html代码)

HTTP/1.1 200 OK //响应行,其中200为响应代码,它标示了响应的状态,

Last-Modified: Mon, 20 Dec 2002 23:26:42 GMT //以下为响应头标
Date: Tue, 11 Jan 2003 20:52:40 GMT
Status: 200
Content-Type: text/html
Servlet-Engine: Tomcat Web Server/5.0
Content-Length: 59
   
<html> //以下为响应体
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

2.关于请求的参数的传递方法
在一个请求中,有用的请求信息就是请求参数,它是一种map,由键-值对构成.
这些参数的传递方法有两种:GET和POST.
对于这两种方法的不同之处在于:
1) GET方法将参数转换为查询字串,把它们加在指定的URL之后,中间有用问题连接,然后传送至
指定的程序做处理.
2) POST方法将参数做为请求体的一部分传递出去.在URL中看不到相关的信息.
一般来说get方法用于传送信息量较少的请求(少于255个字符)
而POST而用于传送信息量很大的请求.另外在传递用户名称和密码时,为防止它们出现在URL
中,应使用POST方法.

3.所有的控件必须放在<form>.....</form>之中.


2007-4-19
_____________________________________________________________________________________________________________________
1.关于jsp指令.(page/include/taglib)

a directive doesn't directly affect the content of the response sent to the browser, but it tells the container how it should handle the page

一个jsp指令并不会影响送至浏览器的响应的具体内容,但是它会告诉容器应该如何处理这个页面

 

2009-8-10

 

 

1.关于Servlet的生命同期

The servlet is normally
created when a user first invokes a URL corresponding to the servlet, but you
can also specify that the servlet be loaded when the server is first started。

Servlet默认是延迟加载的,即只有请求第一次委派到这个Servlet上时,Servlet容器才会创建这个Servlet的实例,然后调用init方法进行初始化。此后再有请求到达时,容器会新起一个线程或是从线程池中分配一个闲置线程,在该线程中进行service方法,而service方法的主要工作就是查看HTTP请求,找出是由哪种方法提交的请求(比如:GET,POST等等),然后调用相应的doXXX方法处理请求。

以下servlet生命周期示意图:

 

2.关于Servlet的类层次结构

 

3.关于HttpServletRequest和HttpServletResponse

 

Q: Who implements the interfaces for HttpServletRequest and HttpServletResponse? Are those classes in the API?
A: The Container, and No. The classes aren’t in the API because they’re left to the vendor to implement. The good news is, you don’t have to worry about it. Just trust that when the service() method is called in your servlet, it’ll be handed references to two perfectly good objects that implement HttpServletRequest and HttpServletResponse. You should never care about the actual implementation class name or type. All you care about is that you’ll get something that has all the functionality from HttpServletRequest and HttpServletResponse.
In other words, all you need to know are the methods you can call on the objects the Container gives you as part of the request! The actual class in which they’re implemented doesn’t matter to you—you’re referring to the request and response objects only by the interface type.

 

记住:HttpServletRequest和HttpServletResponse都是接口,平台API中没有任何这两个接口的实现类,它们的实现类都是由Servlet容器定义和创建的,对于开发人员来说,并不需要了解这些,只要使用接口就OK了。

 

4.为什么会有GenericServlet 、ServletRequest 、 ServletResponse?而不是只保留http打头的那些对应类呢?

Q: I’m still confused about why there’s a GenericServlet and ServletRequest and ServletResponse. If nobody’s doing anything except HTTP servlets... then what’s the point?
A: We didn’t say nobody. Somebody, somewhere, one could imagine, is using the servlet technology model without the HTTP protocol. Just nobody we’ve met personally or read about. Ever.
Still, the flexibility was designed into the servlet model for those who might want to use servlets with, say, SMTP or perhaps a proprietary custom protocol. The only support built-in to the API, though, is for HTTP, and that’s what virtually everyone’s using.

原因在于:原则上讲Servlet技术并不只是单单同http协议工作的,理论上讲Servlet能和应用层的各种协议工作,比如SMTP,FTP,Talnet等等。这就是设计GenericServlet 、ServletRequest 、 ServletResponse的用意,可以由他们扩展出像FTPServlet,FTPRequest这样的类来,使得Servlet可以和其他应用层协议工作。

 

 

 

5.关于Servlet生命周期和Request的重点:

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Laurence 

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值