Advertisement
AnindyaBiswas

FirstServlet

Oct 18th, 2022
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package test;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5.  
  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11.  
  12. /**
  13.  * Servlet implementation class FirstServlet
  14.  */
  15. @WebServlet("/FirstServlet")
  16. public class FirstServlet extends HttpServlet {
  17.     private static final long serialVersionUID = 1L;
  18.  
  19.     /**
  20.      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  21.      */
  22.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  23.         // TODO Auto-generated method stub
  24.         //response.getWriter().append("Served at: ").append(request.getContextPath());
  25.        
  26.         //My Code
  27.         response.setContentType("text/html");
  28.         PrintWriter pw = response.getWriter();
  29.        
  30.         String name1 = request.getParameter("fname");
  31.         String name2 = request.getParameter("lname");
  32.         pw.println("Welcome " + name1 +" " + name2);
  33.         pw.close();
  34.        
  35.     }
  36.  
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement