Java Servlets

What are Java Servlets ?

Last updated:7/9/2018 2:08:30 AM

1 Answers

Prakash nidhi Verma
Prakash nidhi Verma

Java Servlets :

A programs that run on a Web and Application server is callled Java servelts which is act as a middle layer between a request coming from a Web browser or other HTTP client and Database. we can directly collect input from users through web page forms by using servlet 

- Common Gateway Interface (CGI). 

- Performance is significantly better. 

- Servlets execute within Web server space. 

- Its security test is good and its having independent platform. 

import java.io.*; 
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class public class HelloWorld extends HttpServlet {
   private String message;
   public void init() throws ServletException {
      // Do required initialization
      message = 'Mindstick';
   }
   public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
      // Set response content type
      response.setContentType('text/html');
      // Actual logic goes here. PrintWriter out = response.getWriter();
      out.println('<h1>' + message + '</h1>');
   } public void destroy() {
      // do nothing.
   }
}

Answer