0% found this document useful (0 votes)
36 views6 pages

ExptNo 7 11 12 13

The document outlines a curriculum for an Advanced Java Programming course, focusing on servlet development and related experiments. Key experiments include creating servlets for user login, state management, and database registration using JDBC. It also discusses servlet lifecycle, advantages over CGI, and provides references for further study.

Uploaded by

Saniya Bonde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views6 pages

ExptNo 7 11 12 13

The document outlines a curriculum for an Advanced Java Programming course, focusing on servlet development and related experiments. Key experiments include creating servlets for user login, state management, and database registration using JDBC. It also discusses servlet lifecycle, advantages over CGI, and provides references for further study.

Uploaded by

Saniya Bonde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

TE Elective-II Advanced Java Programming (2019 Course) TE. (E&TC) Sem.

- II

PVG's College of Engineering and Technology & G. K. Pate (Wani) Institute of


Management, Pune-411009
Accredited by NAAC with Grade “A”
Department of Electronics and Telecommunication Engineering
___________________________________________________________________________
Experiment 7:. A. Write Servlet (procedure for client side) to display the username and
password accepted from the client.
B. Write Servlet (procedure for server side) to display the username and password accepted
from the client.
Experiment 11:.Create login form and perform state management using Cookies, HttpSession
and URL Rewriting.
Experiment 12:. Create a simple calculator application using servlet.
Experiment 13:. Create a registration servlet in Java using JDBC. Accept the details such as
Username, Password, Email, and Country from the user using HTML Form and store the
registration details in the database.

Student Name: Class: T.E. Division: I / II


Roll No: Date of Submission:
Marks Obtained: /20 Signature of the subject teacher:
___________________________________________________________________________
Aim:
7:. A. Write Servlet (procedure for client side) to display the username and password accepted
from the client.
B. Write Servlet (procedure for server side) to display the username and password accepted
from the client.
11:.Create login form and perform state management using Cookies, HttpSession and URL
Rewriting.
12:. Create a simple calculator application using servlet.
13:. Create a registration servlet in Java using JDBC. Accept the details such as Username,
Password, Email, and Country from the user using HTML Form and store the registration
details in the database.

Objective: to learn servlet in JAVA

Mapped Outcome: After completing the experiment, the students will be able to: CO6.
Develop program for client /server communication using Java Servlet classes.

Software tools required: Eclipse/ Neatbean/IntelliJ IDEA

Theory:

A servlet is a Java programming language class that is used to extend the capabilities of
servers that host applications accessed by means of a request-response programming
model. Although servlets can respond to any type of request, they are commonly used to extend
the applications hosted by web servers. For such applications, Java Servlet technology defines
HTTP-specific servlet classes.

Say No to Plagiarism and Yes to Acknowledgements Green Revolution No Pollution


NDC
TE Elective-II Advanced Java Programming (2019 Course) TE. (E&TC) Sem. - II

The javax.servlet and javax.servlet.http packages provide interfaces and classes for
writing servlets. All servlets must implement the Servlet interface, which defines life-cycle
methods. When implementing a generic service, you can use or extend the GenericServlet class
provided with the Java Servlet API. The HttpServlet class provides methods, such
as doGet and doPost, for handling HTTP-specific services.

Properties of Java Servlet


The properties of Servlets are as follows:
• Servlets work on the server side.
• Servlets are capable of handling complex requests obtained from the web server.
Servlet Life Cycle
Java Servlet has a pre-defined lifecycle starting from initializer (memory allocation) until
the object is destructed (memory deallocated). It takes place in following steps :
1. init() – is called as soon as the request is received by the web server and a new
servlet instance is initialized.
2. service() – to handle client request and redirect the request to an appropriate
doGet() or doPost()
3. destroy() – called when the request is handled, response sent back to the client
and finally the memory allocated to the servlet is deallocated.

The life cycle of a servlet is controlled by the container in which the servlet has been deployed.
When a request is mapped to a servlet, the container performs the following steps.

1. If an instance of the servlet does not exist, the web container


2. Loads the servlet class.
3. Creates an instance of the servlet class.
4. Initializes the servlet instance by calling the init method. Initialization is covered in
Initializing a Servlet.
5. Invokes the service method, passing request and response objects. Service methods are
discussed in Writing Service Methods.
6. If the container needs to remove the servlet, it finalizes the servlet by calling the
servlet’s destroy method. Finalization is discussed in Finalizing a Servlet.

Say No to Plagiarism and Yes to Acknowledgements Green Revolution No Pollution


NDC
TE Elective-II Advanced Java Programming (2019 Course) TE. (E&TC) Sem. - II

Execution of Java Servlets


Execution of Servlets basically involves Six basic steps:
1. The Clients send the request to the Web Server.
2. The Web Server receives the request.
3. The Web Server passes the request to the corresponding servlet.
4. The Servlet processes the request and generates the response in the form of
output.
5. The Servlet sends the response back to the webserver.
6. The Web Server sends the response back to the client and the client browser
displays it on the screen.

Difference between Java Servlets and CGI


Servlet CGI (Common Gateway Interface)
Servlets are portable and efficient. CGI is not portable.
In Servlets, sharing data is possible. In CGI, sharing data is not possible.
Servlets can directly communicate with the CGI cannot directly communicate with the
webserver. webserver.
Servlets are less expensive than CGI. CGI is more expensive than Servlets.
Servlets can handle the cookies. CGI cannot handle the cookies.
Servlets APIs
Servlets are built from two packages:
• javax.servlet(Basic)
• javax.servlet.http(Advance)
Various classes and interfaces present in these packages are:
Component Type Package
Servlet Interface javax.servlet.*
ServletRequest Interface javax.servlet.*
ServletResponse Interface javax.servlet.*
GenericServlet Class javax.servlet.*
HttpServlet Class javax.servlet.http.*
HttpServletRequest Interface javax.servlet.http.*
HttpServletResponse Interface javax.servlet.http.*
Filter Interface javax.servlet.*
ServletConfig Interface javax.servlet.*
Advantages of a Java Servlet
• Servlet is faster than CGI as it doesn’t involve the creation of a new process for
every new request received.
• Servlets, as written in Java, are platform independent.

Say No to Plagiarism and Yes to Acknowledgements Green Revolution No Pollution


NDC
TE Elective-II Advanced Java Programming (2019 Course) TE. (E&TC) Sem. - II

• Removes the overhead of creating a new process for each request as Servlet
doesn’t run in a separate process. There is only a single instance that handles all
requests concurrently. This also saves the memory and allows a Servlet to easily
manage the client state.
• It is a server-side component, so Servlet inherits the security provided by the
Web server.
• The API designed for Java Servlet automatically acquires the advantages of the
Java platforms such as platform-independent and portability. In addition, it
obviously can use the wide range of APIs created on Java platforms such
as JDBC to access the database.
• Many Web servers that are suitable for personal use or low-traffic websites are
offered for free or at extremely cheap costs eg. Java servlet. However, the
majority of commercial-grade Web servers are rather expensive, with the
notable exception of Apache, which is free.

Java™ servlets and Java server pages (JSPs) are Java programs that run on a Java application
server and extend the capabilities of the Web server.
Java servlets are Java classes that are designed to respond to HTTP requests in the context of
a Web application.
You can look at JSPs as an extension of HTML that gives you the ability to seamlessly
embed snippets of Java code within your HTML pages. These bits of Java code generate
dynamic content, which is embedded within the other HTML/XML content. A JSP is
translated into a Java servlet and executed on the server. JSP statements embedded in the JSP
become part of the servlet generated from the JSP. The resulting servlet is executed on the
server.
The HTTP Server does not run Java Web applications directly. HTTP requests for Java
applications are forwarded by the HTTP Server to Java application servers.

Procedure:
1. Draw UML Diagram
2. Compile the written code.

Results: Attach the print of code and output of program.

Conclusion:……………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
……………
Remarks by Subject teacher about correctness and improvements:

…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………

Say No to Plagiarism and Yes to Acknowledgements Green Revolution No Pollution


NDC
TE Elective-II Advanced Java Programming (2019 Course) TE. (E&TC) Sem. - II

Reference:

1. Herbert Schildt, “Java: The complete reference”, Tata McGraw Hill, 7th Edition
2. Jim Keogh, “Complete Reference J2EE” , Enterpr
3. E. Balaguruswamy, “Programming with JAVA: A Primer” McGraw Hill Education, India, 5th
Edition.
4. “Java 6 Programming”, Black Book, Dreamtech
5. “Java Server Programming, Java EE6 (J2EE 1.6)”, Black Book, Dreamtech
6. M.T. Savaliya,“Advanced Java Technology”, Dreamtech
7. https://docs.oracle.com/javaee/7/tutorial/
8. NPTEL Course “Programming in Java” Link of the Course:
https://nptel.ac.in/courses/106/105/106105191/

Important Notes:

Note1. Following points should be considered while writing the conclusion: benefits of Servlet
and JSP.
Note2.Print all the documents back to back on every page. Save pages to save trees.
Note3.Printing on single side will reduce the marks
Note4.Plagiarism of any form is strictly prohibited and attract towards reduction in marks
Note4.Submit the assignments well in time i.e. within four days of performing the experiment
to get maximum marks.

Sign Submission Attendance(10) Submission(5) Understanding Total


Date (5) (20)

Say No to Plagiarism and Yes to Acknowledgements Green Revolution No Pollution


NDC
TE Elective-II Advanced Java Programming (2019 Course) TE. (E&TC) Sem. - II

UML Diagram:

Say No to Plagiarism and Yes to Acknowledgements Green Revolution No Pollution


NDC

You might also like