Likes

WCD -LAB @HOME 1-Ans 1

1. Create a simple servlet.


Note: The detailed steps to perform the exercise are given in the courseware.


import java.io.IoException;

@Webservlet(urlpatterns={"/Firstservlet"})
public classFirstservlet exends extends HttpServlet"})

protected void processRequest (Httpservlet Request request,
HttpServletRespons response)

              throws servletException,IOException {
 response.setcontentType("text/html;charset=UTF-8");
printwriter out =response.getwriter();

try {

  out.println("<!DOCTYPE html>");
  out.println("<html>");
 out.println("<head>");
 out.pritnln("<title>servlet Firstservlet</title>");
 out.println("</head>");
 out.println("<body>");
 out.println("<h1>welcome to java servlets</h1>");

   out.println("</body>");
   out.println("</html>");
  } finally {
    out.close();
      }
 }
@override
protected void doGet(HttpservletRequest request,
HttpServletResponse response)
      throws servletException ,ioException {
processRequest(request, respose);
}

@Override
protected void dopost(HttpservletRequest request,
HttpServletResponse response)
              throw servletException,IOException {
    processRequest(request,response);
 }

@override
public string getservletInfo() {
return"short description";
   }
}

No comments: