Вы находитесь на странице: 1из 8

1Why use servlets and JSP.

Flexible scalable architecture

What do you mean by Flexible Scalable Architecture

Scalability
Scalability is the capability to increase resources to yield a linear (ideally) increase in service capacity. The key
characteristic of a scalable application is that additional load only requires additional resources rather than
extensive modification of the application itself.
Although raw performance makes a difference in determining the number of users that an application can support,
scalability and performance are two separate entities. In fact, performance efforts can sometimes be opposed to
scalability efforts.

How Web Clients and Web Servers talk to each other?


Clients and servers talk using HTTP and browsers know HTML
Client clicksbrowser formats the request and sends to serverserver finds the
resource(pdf,html,image,etc)formats the result and sends it to browserbrowser gets the HTMl and
displays it to user

1.
2. Gazillions of clients
3. Web server takes a request and gives something back to the client or 404
error not found

4. Web Client lets the user request something on the server and shows the user
the result of the request
5. Clients and Servers know HTML and HTTP
a. Talk using HTTP(mostly)
b. Client understands HTML
6. HTTP runs on top of TCP/IP
a.
b.
c.
d.
e.

Tcp : makes sure a file sent from one end is received as a complete file
Ip : routing of packets
http : request/response communication b/w client and server
request : url, method(get,post,etc),form parameters(required by method on server
side)
response : status code,content-type,content

7. HTTP Response
a. HTML browser uses header info to process the HTML page
b. HTTP adds this header info in response

8. Get And Post


a. With get u request something and server gives it back
b. Post lets u send form data along with requesting something,its get++.
c. With get u can send form data but amount of characters is limited
based on server
d. The data u send get appended at the end of URL,desired???
e. Coz of above users cant bookmark,desired???
f. ?color=dark&taste=awesome
9. Get Vs Post(http://www.cs.tut.fi/~jkorpela/forms/methods.html)
a. Difference lies in data encoding :
b. Get should be used if form processing is idempotent,pure query form.
c. There are however reasons to use post even for idempotent requests
,coz of problems related to long URLs and non-ASCII character in form
data
d. Post may involve updating , storing,ordering and sending email
10.Anatomy of HTTP get request

11.Anatomy of HTTP post Request


a. Has payload which is form data and is present in body,which is given to
requested resource.

12.Parts of URl
a.

Protocol,server,optional port,path,resource,request parameters(for get request E.g :


http://www.wickedlysmat.com:80/beeradvice/select/beer1.html

13.TCP Port
a. 16 bit number(0-65535): FTP 21, Telnet 23 , SMTP 25 , Pop3 110 , HTTPS 443 , HTTP
b.
c.
d.
e.

80 , Time 37
Logical connection to Http s/w running on machine
0-1023 are reserved for well known services
Without port numbers a server wont know which app a client wanted to connect to
So if a web browser landed at POP3 ,server does not know how to parse HTML and
even if it did ,it cannot send an HTML response

14.Anatomy of HTTP response


a. Header info tells the browser : protocol being used, whether the
request was successful and kind of content included in the body.
b. Body contains content(HTML) for browser to render

15.2 things web server cant do alone


a. Dynamic content : web server serves only static pages,it needs a
helper app to build just in time pages
b. Saving data on the server : it need another app to process form data
and save it to a file or db
16.Non-java term for a helper app is cgi : its written in perl , but other languages
c python or php can also work.It works like this : user clicks a link that has a
link to a CGI program instead of a static web page.Web server sees that the
request is for a CGI, so it launches and runs the program.The program is also
sent any parameters from method GET or POST,it constructs the HTML and
the web server returns after shutting down the helper app
17.CGI vs Servlets
a. For perl server has to launch a heavy weight process for every request
b. But evry instance of jvm is also heavy weight
c. But servlets stay loaded and separate requests for servlets are
handled as separate threads of a single running servlet, theres no
overhead of starting the jvm,loading the class and so on
d. But web servers are able to keep single perl program running between
client requests
e. but all web servers cannot do this
f. Also a servlet can be a J2EE client, i.e it can participate in security and
transactions, along with enterprise beans,
18.Putting html in servlet is error prone

a. You cant have carriage return inside a String literal,not a real one
b. HTML almost always has double quote marks, that tells java its the
end of String literal, which marks the end of String literal, hence it has
to be escaped as well
19.Thus the solution Java inside HTML
a. Isnt that a problem for HTML designers : no coz if they according to
latest JSP spec and by following best practices,page designers would
be putting very little Java, they have to put labels which call java,they
have to learn JSP syntax

Вам также может понравиться