struts2 in action笔记(一)

struts2 in action笔记(一)

先复习下JAVA SERVLET API:
servlet API使HTTP直接面向java平台,这一意味着java开发人员能一种直观的方式写HTTP server 代码,这种方式是对HTTP client/server通讯模式的面向对象的抽象。Servlet API有三个核心部分:servlet, request以及response 对象。A servlet is a singleton Java object whose whole purpose is to receive requests and return responses after some arbitrary back-end processing. The request object encapsulates the various details of the request, including the all-important request parameters as submitted via form fields and querystring parameters. The response object includes such key items as the response headers and the output stream that will generate the text of the response. In short, a servlet receives a request object, examines its data, does the appropriate back-end magic, and then writes and returns the response to the client.抽时间看下Servlet Specification,他规定API必须遵守的设计规则(具体实现是由第三方的servlet 容器提供的,容器既可以是独立的,比如tomcat,也可以是一些更大的application server的一部份)。部署servlet之前,必须按规则打包,最基础的打包单位是web application。Servlet Specification defines a web application as “a collection of servlets, HTML pages,classes, and other resources.” servlet容器收到请求后会决定哪一个servlet处理请求,调用该servlet的service()方法,传给他request和response作为参数。Servlet API有三个关键角色:servlets,web applications, and the servlet container。一个servlet container可以拥有多个web applications。Servlet API还提供一些重要的高层功能,像session机制,他能把某一客户的相关的请求都联系起来(不要忘了HTTP的stateless特性),Without it, we’d be handling cookies and parsing embedded querystring session keys.(这个没有完全理解,cookies 里是不是嵌入了查询条件参数等?)。Servlet API直接以一种面向对象抽象的方式封装client/sever交换模式,这样我们就不需要亲历亲为的解析HTTP请求,事实上我们收到的是一个整洁的用java封装的request对象。说这些,最终是要强调the Servlet API is an infrastructure-level technology in the scope of modern web applications. As infrastructure, servlets provide the solid low-level foundation upon which robust web applications can be built. If you consider the routine needs of a web application, the Servlet API doesn’t attempt to provide solutions for such things. Now that we know what servlets can do,let’s look at what they leave undone. These common tasks of the domain are what a web application framework like Struts 2 will need to address.
    The execution of an interceptor can be broken into three phases: preprocessing, passing control on to the rest of the action invocation by calling invoke(), and postprocessing. Interceptors can also divert workflow by returning a control string instead of calling invoke().They also have access to all key data via the ActionInvocation instance they receive.Ultimately, interceptors can do just about anything.

你可能感兴趣的:(struts2 in action笔记(一))