0% found this document useful (0 votes)
3 views

ex5a-servletfrom html form

servletfrom html form

Uploaded by

Mr.Sakthivel csg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

ex5a-servletfrom html form

servletfrom html form

Uploaded by

Mr.Sakthivel csg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Ex-5a.

Servlets:to invoke servlets from html Forms


index.html
----------
!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Http servlet demo</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>
<a href="welcome">click to call servlet</a>
</h1>
</body>
</html>

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>

You might also like