MVC简介

我们通常用http server来代表对来着浏览器客户端的请求作出相应的server。而web server可能还指包括硬件等等。

the web server applications serves only static pages,因此如果客户端请求一个动态页面,例如返回一个包含当前时间的html,http server是处理不了的。

因此http server需要调用所谓的helper application帮助生成静态页面,然后由http server返回给客户端。


什么是servelet

非java的helper app称之为CGI programs.  Most CGI programs are written as Perl scripts, but many other languages can work including C, Python and PHP.(CGI stands for Common Gateway Interface)
Servlets and CGI both play the role of a helper app in the web server.  Helper app returns a static page to web server.

在返回这个page的时候,可以用println拼一个html出来,也可以 用jsp。


例如:
http://localhost:8080/ch1/Serv1 这个是servelet的名字
当web server 发现请求的是helper app而不是静态页面时,就会自动launch helper app.

a typical servlet is a class that extends httpServletRequest and overrides one or more service methods that correspond to HTTP methods invoked by the browser (doGet() doPost() etc)


什么是container

Servlets don't have a main() method.  They are under the control of another java app called a container.
when your web server app (like Apache) gets a request for a servlet, the server hands the request not to the servlet itself, but to the container in which the servlet is deployed.
It's the container that gives the servlet the http request and response, and it's the container that calls the servlet's methods (like doPost() or doGet(HttpServeltRequest, HttpServeletResponse))

The container runs multiple threads to process multipul requests to a single servlet. 也就是说,一个servlet只有一个实例。

and every client request generates a new pair of request and response objects.


什么是jsp (JavaServer page)

a JSP page looks just like an HTML page, except you can put java and java-related things inside the page.

而 container takes what you've written in your JSP, translate it into a servlet class source (.java) file, then compiles that into a Java servlet class.  After that, it is just servlets all the way down.
MyJSP.jsp->MyJSP_jsp.java->MyJSP_jsp.class-MyJSP_jsp servlet

那么为什么要使用JSP呢?

1,首先JSP使得html内容的生成和显示分开了。

2,让servlets更容易重用,而不是为每个动态页面专门定制一个。

3,使用JSP比使用servlets,对网页设计人员来说简单的多。他只需要在html适当的位置调用java就可以了。


什么是mvc (model view controller)

mvc is a design pattern. There're also other design patterns.

servlet -- controller
jsp -- view
java classes -- model

我们已经知道servelet和jsp的作用了,那么为什么这里又出现了一个java class呢?

因为business logic should not be stuffed inside servlets,有两个原因:

1,Because you should never assume that your business logic will be accessed only from the web!

2,Business logic is always changing。

同时为了使这些java classes尽可能的被重用,一般被设计成POJO(plain old java object)即最简单的java类,没有任何其他依赖的框架。因此大部分情况下就是javabeans。


现在再具体的说MVC每个部分的作用:




最后说一下什么是DD

web.xml

DD--deployment descriptor the map URLs to servlets used for container how to run your servlets and JSPs.  The name of dd is web.xml




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值