Module3 - Server Side Programming
Module3 - Server Side Programming
•Monitor Activities
•Implement Accessibility
•Programming Flexibility
•Record Data
•Feasibility
•Security
Disadvantages of Server Side Programming
•Can be drastically slow
•For eg. a Servlet might take data entered by the user in HTML order
entry form and apply the business logic to update a company’s order
database.
Functionality of Servlets
•It can manage and store the data submitted by an HTML form.
•It can provide dynamic response to HTTP request, for e.g., it can
return the result of a database query to the client.
•It can read the data entered by the client in a form and look for any
additional information embedded in the HTTP request.
•It can prepare a response to send it back to the client. The response
could be in text form, binary form or a zip file.
Java Servlet Architecture
Java Servlet Architecture
Execution of Servlets basically involves six basic steps:
•The clients send the request to the web server.
•The web server receives the request.
•The web server passes the request to the
corresponding Servlet.
•The Servlet processes the request and generates the
response in the form of output.
•The Servlet sends the response back to the web server.
•The web server sends the response back to the client
and the client browser displays it on the screen.
Classes of Java
Java Servlet Architecture
Life Cycle of Servlet
Servlet life cycle contains five steps:
1) Loading of Servlet
2) Creating instance of Servlet
3) Invoke init() once
4) Invoke service() repeatedly for each client request
5) Invoke destroy()
GET & POST Methods
GET is used to request data from a specified resource.
GET is one of the most common HTTP methods.
Query string (name/value pairs) is sent in the URL of a GET
request.
e. g /test/demo_form.php?name1=value1&name2=value2
GET requests remain in the browser history
This method must not be used if you have a password or
some sensitive information to be sent to the server
GET requests have length restrictions
GET requests are only used to request data (not modify)
It is better for data that is not secure. It cannot be used for
sending images or word documents.
GET & POST Methods
POST is used to send data to a server to create/update a
resource.
E.g: POST /test/demo_form.php HTTP/1.1
Host: facebook.com
name1=value1&name2=value2
POST requests do not remain in the browser history
POST requests have no restrictions on data length
It helps you to securely pass sensitive and confidential
information like login details to server.
POST method takes lots of time when uploading the large binary
file.
This method is a little safer than GET because the
parameters are not stored in browser history.
GET vs. POST Method
GET POST
Data is visible to everyone in the URL Data is not displayed in the URL
GET requests are often used for POST parameters are often used for
fetching documents. updating data for actually making
changes to the server.
GET method supports only string POST method supports different data
data types types, such as string, numeric, binary,
etc.
A session ends when the user closes the browser or after leaving
the site, the server will terminate the session after a
predetermined period of time, commonly 30 minutes duration.
Session Handling
It can also transfer the information in the form of value from
one web page to another.
Whenever a user visits a website for the first time, the site sends
packets of data in the form of a cookie to the user's computer.
Cookies are created and shared between the server and browser
with the help of an HTTP header.
Cookies
Cookies are text files stored on the client computer and they
are kept of use tracking purpose. Server sends a set of cookies
to the browser.
The session ends when the user logout Cookies end on the lifetime set by the user.
from the application or closes his web
browser.
It can store an unlimited amount of data. It can store only limited data.
Sessions are more secured compared to Cookies are not secure, as data is stored in
cookies, as they save data in encrypted a text file, and if any unauthorized user
form. gets access to our system, he can tamper
the data.
Sessions can store any type of data. Cookies can only store strings.
Java Server Pages (JSP)
Java Server Pages (JSP) is a server side technology for developing
dynamic web pages.
JSP is an extension of servlets and every JSP page first gets converted
into servlet by JSP container before processing the client’s request.
The JSP pages are easier to maintain than Servlet because we can
separate designing and development.
The JSP tags which allow java code to be included into it are <% ----
java code----%>.
Java Server Pages (JSP)
This is mainly used for implementing presentation layer (GUI
Part) of an application.
A complete JSP code is more like a HTML with bits of java code
in it.
In JSP, we can use many tags such as action tags, JSTL, custom
tags, etc. that reduces the code.
Java Server Pages (JSP)
JSP takes care of exception handling. Servlet does not take care
of exception handling. It is the responsibility of programmers.