Servlet Summary



–> A servlet is a Java class that runs on a server, and a servlet for a web application extends the HttpServlet class.

–> When you write servlets , you override the doGet and doPost methods to provide the processing that’s required. These methods receive the request object and the  response object that are passed to them by the server.

–> After you use the setContentType method of the response object to set the content type of the response that’s returned to the browser, you use the getWriter method  to create a PrintWriter object. Then, you can use the println and print methods of  that object to send HTML back to the browser.

–> The class files for servlets must be stored in the WEB-INF\classes directory of an  application or in a subdirectory that corresponds to a package name.

–> To request a servlet from a URL, you include the word “servlet” after the document root directory in the path. This is followed by the package name, a dot, and the servlet name.

–> You can override the init method of a servlet to initialize its instance variables. These variables are then available to all of the threads that are spawned for the one instance of the servlet.

–> When you code a thread-safe servlet, you prevent two or more users from accessing  the same block of code at the same time.

–> To print debugging data to the server console, you can use the println method of  the System.out or System.err object. An alternative is to use the log methods of the  HttpServlet class to write debugging data to a log file.

Random Posts

  • Creating a SessionFactory Using Hibernate
  • Difference between Interface and Abstract Class
  • Difference between #include and Import
  • Difference between session.save() , session.saveOrUpdate() and session.persist()
  • Explain Session tracking using Servlet

Post a Comment