what is servlet ? discuss different API's used in servlet programming. demonostrate with example.
java servlet is the server-side program that runs on a web server and handles clients request and returns a dynamic response to each request. the dynamic response could be based on user's input and with data retrieved from a database or other applications or time-sensitive data (such as news and stock prices).
the javax.servlet and javax.servlet.http packages interfaces and classes for servlet API. The javax.servlet package contains many interfaces and classes that are used by a servlet or web container. There are many interfaces in javax.servlet package. Some of them are: servlet, servlet request, servletResponse, servletConfig, servletContext etc. Besides this, there are many classes in javax.servlet package. Some of them are:
GenericServlet, ServletInputStream ServeletOutputStream, ServletRequestWrapper etc.
a) Servelet Interfaces: Example:-
import java.io.*;
import javax.servlet.*;
public class servlet implements servlet
{
servletConfig config =null;
public void in("servlet is initialized");
}
public void service(ServletRequest req, ServletResponse res) throws IOException, ServletException
{
res.SetConnectionType("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 distroyed");}
public ServletConfig getServletConfig(){return config;}
public string getServletInfo(){return"Implementating servlet interface";}
}
the javax.servlet and javax.servlet.http packages interfaces and classes for servlet API. The javax.servlet package contains many interfaces and classes that are used by a servlet or web container. There are many interfaces in javax.servlet package. Some of them are: servlet, servlet request, servletResponse, servletConfig, servletContext etc. Besides this, there are many classes in javax.servlet package. Some of them are:
GenericServlet, ServletInputStream ServeletOutputStream, ServletRequestWrapper etc.
a) Servelet Interfaces: Example:-
import java.io.*;
import javax.servlet.*;
public class servlet implements servlet
{
servletConfig config =null;
public void in("servlet is initialized");
}
public void service(ServletRequest req, ServletResponse res) throws IOException, ServletException
{
res.SetConnectionType("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 distroyed");}
public ServletConfig getServletConfig(){return config;}
public string getServletInfo(){return"Implementating servlet interface";}
}
Comments
Post a Comment