1. Web应用开发概述

本文介绍了Web应用的基本架构,包括浏览器-服务器模型的工作流程,详细解释了HTTP协议下GET与POST方法的区别,以及如何通过这些方法发送数据。同时,还探讨了服务器如何响应请求并返回数据给客户端,以及会话管理中Cookie的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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












评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值