Write a servlet program that takes your name and address from an HTML form and display it.
web.xml
Application | ||||
index.html
|
web.xml
<web-app>
<servlet>
<servlet-name>Display</servlet-name>
<servlet-class>Display</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Display</servlet-name>
<url-pattern>/Display</url-pattern>
</servlet-mapping>
</web-app>
Disply.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Display extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
String name=request.getParameter("name");
String address=request.getParameter("address");
pw.write("<br>Name : "+name);
pw.write("<br>Address : "+address);
pw.close();
}
}
index.html
<html>
<head>
<title>Display</title>
</head>
<body>
<form method="post" action="Display">
Name : <input type="text" name="name" value="" /><br/>
Address : <input type="text" name="address" value="" /><br/>
<input type="submit" value="Submit" />
</form>
</body>
</html>
Comments