Shri Kanaskar | ||||||||||
A SERVLET Example | ||||||||||
This is an example of Servlet displays the Request method used by client. BasicServlet.java import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class BasicServlet extends HttpServlet { public void init(ServletConfig config) throws ServletException { super.init(config); //Always pass the servletconfig object to the upper class } public void doGet(HttpServletRequest request,Httpservletresponse) throws servletException, IOException { response setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD><TITLE>Basicservlet</TITLE></HEAD>"); out.println("<BODY>)"; out.println("Your method = " + request.getMethod() + "/n"); out.println("<BODY></HTML>"); out.close(); } public void doPost(HttpServletRequest request,Httpservletresponse) throws servletException, IOException { response setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD><TITLE>Basicservlet</TITLE></HEAD>"); out.println("<BODY>)"; out.println("Your method = " + request.getMethod() + "/n"); out.println("<BODY></HTML>"); out.close(); } public String getServletInfo() { //Get Servlet information return "basicservlet information"; } } |
||||||||||
You can this Servlet in within <form> tag of HTML <FORM Action = http://localhost/servlet/Basicservlet METHOD=POST> ------------- <FORM> |