ex5a-servletfrom html form
ex5a-servletfrom html form
NewServlet.java
----------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Creating Http Servlet by Extending HttpServlet class
public class NewServlet extends HttpServlet
{
private String mymsg;
public void init()throws ServletException
{
mymsg ="Http Servlet Demo";
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
// Setting up the content type of web page
response.setContentType("text/html");
// Writing the message on the web page
PrintWriter out= response.getWriter();
out.println("<h1>"+ mymsg +"</h1>");
out.println("<p>"+"Hello Friends!"+"</p>");
}
public void destroy()
{
// Leaving empty. Use this if you want to perform
//something at the end of Servlet life cycle.
}
}
web.xml
--------
<web-app>
<display-name>BeginnersBookServlet</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>MyHttpServlet</servlet-name>
<servlet-class>NewServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyHttpServlet</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>