0% found this document useful (0 votes)
35 views2 pages

Ex - No: 6 (A) HTML To Servlet Program Date: Aim

This document provides an algorithm for writing a Java program to invoke servlets from HTML forms. The algorithm involves: 1) Creating a client-side HTML program with a form containing text fields, a password, submit button, and setting the server URL as the form's action. 2) Writing a Java servlet class that extends GenericServlet and handles requests by getting parameter names and values from the HTML form and sending a response. 3) Compiling the servlet class, running the HTML program, and submitting the form data to the server. The provided program code is an example that adds two numbers submitted through an HTML form to a servlet.

Uploaded by

c.r.dhivyaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

Ex - No: 6 (A) HTML To Servlet Program Date: Aim

This document provides an algorithm for writing a Java program to invoke servlets from HTML forms. The algorithm involves: 1) Creating a client-side HTML program with a form containing text fields, a password, submit button, and setting the server URL as the form's action. 2) Writing a Java servlet class that extends GenericServlet and handles requests by getting parameter names and values from the HTML form and sending a response. 3) Compiling the servlet class, running the HTML program, and submitting the form data to the server. The provided program code is an example that adds two numbers submitted through an HTML form to a servlet.

Uploaded by

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

Ex.

No: 6(a)
Date:

HTML TO SERVLET PROGRAM

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
{

public void doGet(HttpServletRequest request, HttpServletResponse response)


throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String fname = request.getParameter("firstnumber");
String sname = request.getParameter("secondnumber");
int fno = Integer.valueOf(fname );
int sno =Integer.valueOf(sname);
out.println("Addtion totel No:");
out.println( fno+sno);
}
}

You might also like