0% found this document useful (0 votes)
18 views2 pages

Java Servlet Request Handling

x

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 TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Java Servlet Request Handling

x

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 TXT, PDF, TXT or read online on Scribd

FirstServlet processRequest() Method

protected void processRequest(HttpServletRequest request, HttpServletResponse


response) throws ServletException, IOException{
//Retrieving form data from the request
String title = [Link]("title");
String firstName = [Link]("firstName ");
String lastName = [Link]("lastName ");

//concatenating the first and last name


String fullName= firstName + " " + lastName;

//Storing the full name in the request attribute


[Link]("fullName",fullName);

//forwading the request to the SecondServlet


RequestDispatcher dispatcher = [Link]("SecondServlet");
[Link](request,response);
}

_______________

SecondServlet processRequest() Method:

protected void processRequest(HttpServletRequest request, HttpServletResponse


response) throws ServletException, IOException{
//Retrieving the full name from the request
String fullName = (String) [Link]("fullName");

//displaying the full name


[Link]("text/html");
PrintWriter out = [Link]();
[Link]("<html>");
[Link]("<body>");
[Link]("<h1> Full Name: "+ fullName +"</h1>");
[Link]("</body>");
[Link]("</html>");
}

___________________________________________________________________________________
_______________________________
Final Solution:

FirstServlet processRequest() method:

protected void processRequest(HttpServletRequest request,


HttpServletResponse response) throws ServletException, IOException {
String title = [Link]("title");
String firstName = [Link]("firstName");
String lastName = [Link]("lastName");

String fullName = firstName + " " + lastName;

[Link]("fullName", fullName);

RequestDispatcher dispatcher =
[Link]("/SecondServlet");
[Link](request, response);
}

SecondServlet processRequest() method:

protected void processRequest(HttpServletRequest request,


HttpServletResponse response) throws ServletException, IOException {
String fullName = (String) [Link]("fullName");

[Link]("text/html");
PrintWriter out = [Link]();
[Link]("<html>");
[Link]("<body>");
[Link]("<h1>Full Name: " + fullName + "</h1>");
[Link]("</body>");
[Link]("</html>");
}

You might also like