MCA - June, 2007 - 1(i)

Write a servlet program that takes your name and address from an HTML form and display it.





Application

index.html







WEB-INF

web.xml







classes

Display.java


 

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>

No comments:

Popular Posts