Professional Documents
Culture Documents
No: 6(a)
Date:
Aim:
To write a java program to invoke servlets from HTML forms.
Algorithm:
Step1 :Write a client side HTML program (client.html) with the following:
o Insert a <form> that contains the fields such as text, password and one
submit button.
o Set the URL of the server as the value of forms action attribute.
Step2 :Write a java servlet program (server.java) with the following:
o Define a class server that extends the property of the class GenericServlet.
o Handle the request from the client by using the method service() of
GenericServlet class.
o Get the parameter names from the HTML form by using the method
getParameterNames().
o Get the parameter values from the HTML forms by using the method
getParameter().
o Send the response to the client by using the method of PrintWriter class.
Step3: Compile the java source code (server.java).
Step4: Run the HTML program (client.html).
Step5: Submit the form data to the server.
Program:
Addition.html:
<html>
<head>
<title> Addtion of Two Numbers </title>
<body>
<form action = Addtion methed = "GET">
firstnumber <input type =text size =20 name =firstnumber>
second number <input type =text size =20 name =secondnumber>
<input type = submit value = "submit">
</body>
</head>
</html>
Addition.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Addtion extends HttpServlet
{