0% found this document useful (0 votes)
20 views3 pages

Spring 2023 - CS311 - 2

m

Uploaded by

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

Spring 2023 - CS311 - 2

m

Uploaded by

bc210420793mma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment No.

02
Total Marks: 20
Semester: Spring 2023
Topics Covered: 190-214
Introduction to Web Services Development – CS311 Due Date: 13th July, 2023

Instructions:
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if:

 The assignment is submitted after due date.


 The assignment is submitted via email.
 The assignment is copied from Internet or from any other student.
 The submitted assignment does not open or file is corrupt.

Objectives:
To understand and get hands on experience of:

 HTML

 Servlet

Note: All types of plagiarism are strictly prohibited.

For any query about the assignment, contact at [email protected]

Assignment Submission Instructions

You can run and check your complete code in any tool but after that copy/paste your code in
word format (.doc or docx) to upload.
Problem Statement: Marks 20

Write the code for two Java Servlets (processRequest() methods only) in such a way that the user
enters his/her title(Mr, Mrs, Miss), first name and last name and submits the form to the FirstServlet.
FirstServlet concatenates the first name with first and last name with proper space and forwards the
request (using the Request Dispatcher method) to SecondServlet, which displays the full name of the
user.

URL pattern of second Servlet: /SecondServlet

Note: No need to send complete code, just send the code in processRequest() method of each Servlet,
as shown below.

Solution Sample:

FirstServlet processRequest() method:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

String title = request.getParameter("title");

String firstName = request.getParameter("firstName");

String lastName = request.getParameter("lastName");

String fullName = firstName + " " + lastName;

request.setAttribute("fullName", fullName);

RequestDispatcher dispatcher = request.getRequestDispatcher("/SecondServlet");

dispatcher.forward(request, response);

}
SecondServlet processRequest() method:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

String fullName = (String) request.getAttribute("fullName");

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<html>");

out.println("<body>");

out.println("<h1>Full Name: " + fullName + "</h1>");

out.println("</body>");

out.println("</html>");

BEST OF LUCK

You might also like