Advanced Java Programming · Unit 7 · 8 hrs
Servlets and Java Server pages
Exam-focused notes for Servlets and Java Server pages (Advanced Java Programming, CSC419): what the TU syllabus asks and how it has actually been tested, with 17 solved past questions from this unit.
What this unit covers
- Web Container, Introduction to Servlets, Life cycle of servlets, The servlet APIs, Writing Servlet Programs, Reading Form Parameters, Processing Forms, Handling HTTP Request and Response (GET / POST Request), Database Access with Servlets, Handling Cookies and Session
- Servlet vs JSP, JSP Access Model, JSP Syntax (Directions, Declarations, Expression, Scriplets, Comments), JSP Implicit Objects, Object Scope, Processing Forms, Database Access with JSP
- Introduction to Java Web Frameworks
Web Container, Introduction to Servlets, Life cycle of servlets, The servlet APIs, Writing Servlet Programs, Reading Form Parameters, Processing Forms, Handling HTTP Request and Response
Explain the life cycle of servlets. [5]
A Servlet is a small Java program that executes on the server side of a Web connection and dynamically extends the functionality of a web server. All servlets must implement the Servlet interface, which defines the life-cycle methods. The servlet life cycle...
Full solved answer →Explain life-cycle of servlet in detail. Create a simple servlet that reads and displays data from HTML form. Assume form with two fields username and password.[10]
The servlet life cycle defines how a servlet is loaded, initialized, used, and destroyed by the servlet container (e.g., Apache Tomcat). It is managed entirely by the servlet container. --- - When the servlet container starts (or when the first request arri...
Full solved answer →Explain the life cycle of a servlet. [5]
A servlet is a small Java program that executes on the server side of a web connection and dynamically extends the functionality of a web server. All servlets must implement the Servlet interface, which defines the life-cycle methods. The servlet life cycle...
Full solved answer →Define servlet. Discuss life cycle of servlet. Differentiate servlet with JSP. Write a simple JSP file to display 'IOST' 20 times.[10]
--- A servlet is a small program that executes on the server side of a Web connection. Just as applets dynamically extend the functionality of a web browser, servlets dynamically extend the capabilities of a web server. It is a Java programming model used t...
Full solved answer →How do you handle HTTP request (GET) using servlet? [5]
A Servlet handles HTTP GET requests by overriding the doGet() method provided by the HttpServlet class. When a client sends a GET request (e.g., by submitting an HTML form with method="GET" or typing a URL), the web container invokes the doGet() method of t...
Full solved answer →Write short notes on: a. Servlet API b. RMI vs CORBA [2.5+2.5]
--- The Servlet API is a set of Java classes and interfaces provided in the javax.servlet and javax.servlet.http packages that define the contract between a servlet and the servlet container (e.g., Apache Tomcat). Component Type Description --------- Servle...
Full solved answer →Describe the process to deploy the servlet. Write a program to a JSP web form to take input of a student and submit it to second JSP file which may simply print the values of form submission.[10]
--- There are six steps to write and deploy a Servlet program (using Apache Tomcat server): --- Create the required folder structure inside the Tomcat webapps directory: - WEB-INF/classes/ contains compiled .class files - WEB-INF/web.xml is the deployment d...
Full solved answer →Explain the significance of cookies and sessions with suitable example. [5]
A cookie is a small piece of data (key-value pair) stored on the client's browser by the web server. It is used to remember information about the user across multiple HTTP requests, since HTTP is a stateless protocol. - Remembers user preferences (language,...
Full solved answer →Servlet vs JSP, JSP Access Model, JSP Syntax
Write a program in JSP to display the string taken in one page in another page. [5]
This program uses two JSP pages: - Page 1 (input.jsp): Contains an HTML form with a text field where the user enters a string. - Page 2 (display.jsp): Receives the string via HTTP request and displays it. The string is passed from one page to another using ...
Full solved answer →How does JSP differ from Servlet and show the life cycle of Servlet? How do you create and read the cookies and session using JSP? Illustrate with an example.[10]
--- Feature Servlet JSP (JavaServer Pages) --------- Nature Java class that generates HTML HTML page that embeds Java code Extension .java (compiled to .class) .jsp (auto-compiled by container) Writing Style HTML written inside out.println() statements Java...
Full solved answer →What do you mean by JSP implicit objects? Discuss Java Mail API. [5]
--- JSP implicit objects are pre-defined objects that the JSP container automatically makes available to every JSP page without requiring the developer to explicitly declare or instantiate them. These objects can be used directly inside JSP scriptlets and e...
Full solved answer →Define JSP. What are the benefits of using JSP? Create a HTML file with two text fields to first name and last name. Create a JSP file that reads data from the HTML form and display full name.[10]
--- JavaServer Pages (JSP) is a server-side technology used to create dynamic, platform-independent web pages. JSP allows developers to embed Java code directly into HTML pages using special JSP tags. When a JSP page is requested by a client, the server pro...
Full solved answer →Compare JSP with servlet. What are different implicit objects in JSP? [5]
--- Feature Servlet JSP --------- Nature Pure Java code Tag-based approach HTML Writing HTML is written inside Java (Servlet) code Java code is written inside HTML Speed Faster than JSP Slower than Servlet Ease of Coding Writing code is harder Writing code ...
Full solved answer →What is servlet? Write a simple JSP file to display 'Tribhuvan University' five times. [5]
--- A Servlet is a Java program that runs on the server side and is used to handle client requests and generate dynamic web content (typically HTML) as a response. Key points about Servlet: - It is a Java class that extends HttpServlet - It runs inside a Se...
Full solved answer →How forms can be created and processed using JSP? Make it clear with your own assumptions. [5]
JSP (JavaServer Pages) allows embedding Java code inside HTML pages. Forms can be created using standard HTML <form tags within a JSP page and processed by reading the submitted data using JSP's built-in request object. --- Object Purpose ------ request Ret...
Full solved answer →Introduction to Java Web Frameworks
Write short notes on: a. JAVA beans and JAR file b. MVC design pattern [2.5+2.5]
--- A JavaBean is a reusable software component written in Java that follows specific conventions. It is essentially a Java class that encapsulates multiple objects into a single object (the bean). Key Conventions / Properties of a JavaBean: - The class mus...
Full solved answer →Discuss MVC design pattern with example. [5]
MVC (Model-View-Controller) is a software architectural/design pattern that separates an application into three interconnected components. This separation helps in organizing code, improving maintainability, and allowing independent development of each comp...
Full solved answer →Make Unit 7 stick
Practice CSC419 with flashcards & quizzes