您的位置:首页 > 其它

1. Web应用开发概述

2016-12-23 15:05 211 查看
1. Web应用开发概述
浏览器-服务器架构(BS-architecture)
browser/ App ------- request -------> server (database)
<--- response/data --
protocol: HTTP

have a try:

cmd: sudo nc -l 80

browser: type "localhost" as address
these are info that sent to the server(localhost)



now it's waiting for the request
try to type "hello" and ctr+c



"hello" will be displayed in the browser



when we enter the address of a website such as "http://study.163.com"

it is called URL (uniform resource locator) (统一资源定位)
http://study.163.com/smartSpec/intro.html?name=163
http: protocol, such as ftp, mailto

smartSpec/intro.html: request sent to the server

?name=163: data that sent to the server via GET method

Let's see what info can be sent via GET method

<html>
<body>
<form action="http://localhost/form_action.html" method="get">
<p>First Name: <input type="text" name="fname" /></p>
<p>Last Name: <input type="text" name="lname" /></p>
<input type="submit" value="Submit" />
</form>
</body>
</html>


1. open this .html in the browser

2. type sudo nc -l 80 in terminal

3. submit the info
4. result

GET /form_action.html?fname=Lin&lname=Matt



What if we use POST as the method?
same steps as GET
but different result

POST /form_action.html
Content-Length: 20
fname=Lin&lname=Matt
(no extra data shown explicitly after "/form_action.html")
(content-length means the number of charaters(data) sent to the server, which is
fname=Lin&lname=Matt
in this case)



after those info/data/request(shown above) has been sent to the server,

the server needs to give the feedback(response) back to the client/ browser.
feedback: 1. 静态页面(such as .html file, img file)

2. 动态数据 (data retrieved by programs running in the server side based on the input(like first name/ last name in the previous example))

HTTP protocol: 无连接的

after a series of actions has done (request --> response)
the connection gets broken.
for what reason? --> disconnect with those users who are not currently communicating with the server at that time,

in other words, accessible to as many as possible users at the same time

disadvantages: the server does not know who u r.

for example, after we log in, we expect that we do not need to log in again if we try to visit other relevant webpages.

--> solution: cookie

after the first-time connection, the client got a "number" from the server which identifies the client/ browser

then the browser will store that number, and every time when the client connects to the server, it will bring that number with it,
and the server will know the client by that id number

that number in this example is called cookie.

Also, the cookie got its own expiry date, which is set by the server.
HTTP会话 (session)

HTTP protocol: how to deal with the data in the database

background: when the client sends a request to the server, the program in the server always try to retrieve the relevant data from its database system,

after retrieving the data, the program needs to generate a html file (or other file that can be understood by the browser), and sends back to the client as a response.

problem 1: the limitation of the number of connections between the database and the web server is much smaller than that between the client and the web server.

in other words, we need to minimise the number of the connections between the database and the web server.

--> solution1: connection pool

create a connection pool between the web server and the database which has many(limited) connetions
each time when the web server requires a connection to the database, it has to ask the connection pool for the access of connection

--> solution2: cache

different client might search for the same data during a short period of time

there is no need to run the program to retrieve the data from the database each time

lower the workload of the database and speed up the reaction from the server
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: