TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Thursday, 16 April 2020

Servlet Interface In Java | Servlet Interface In Java In Hindi

                        Servlet Interface

Servlet interface provides commonbehaviorto all the servlets.Servlet interface defines methods that all servlets must implement.

Servlet interface needs to be implemented for creating any servlet (either directly or indirectly). It provides 3 life cycle methods that are used to initialize the servlet, to service the requests, and to destroy the servlet and 2 non-life cycle methods.

image of servlet interface

Fig: Servlet Interface In java 

Example by implementing Servlet interface


File: First.java
     import java.io.*;  
     import javax.servlet.*;  
  
    public class First implements Servlet{  
    ServletConfig config=null;  
  
    public void init(ServletConfig config){  
     this.config=config;  
     System.out.println("servlet is initialized");  
}  
     public void service(ServletRequest req,ServletResponse res)  
     throws IOException,ServletException{  
  
r    es.setContentType("text/html");  
  
      PrintWriter out=res.getWriter();  
      out.print("<html><body>");  
     out.print("<b>hello simple servlet</b>");  
     out.print("</body></html>");   
     
     }  
     public void destroy(){System.out.println("servlet is destroyed");}  
     public ServletConfig getServletConfig(){return config;}  
     public String getServletInfo(){return "copyright 2007-1010";}  
      
      }  

No comments:

Post a Comment