0% found this document useful (0 votes)
9 views5 pages

Java Practical22

Uploaded by

Priyanka Thadke
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)
9 views5 pages

Java Practical22

Uploaded by

Priyanka Thadke
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/ 5

Name:- Priyanka Khandu Thadke

Class:-A(CO5I) Roll no:- 60


Practical no:- 22 Write a Servlet program to send username and password using HTML forms and
authenticate the user.
Exercise:-

Q.1)Develop servlet program to retrieve data from List and Radio Button using
HTML Forms.

index.html
<!DOCTYPE html>
<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>
Welcome

<br>
<b
r>
<form action="Form">

Email : <input type="text" name="email"> <br>

User Name: <input type="text" name="uname"> <br>


Password: <input type="password" name="pass"> <br>
Gender : <input type="radio" name="gender" value="male" checked>
Male <input type="radio" name="gender" value="female">
Female <br>

Course: <select name="Course">

<option name="Course">Advanced Java </option>


<option name="Course">Javascript</option>

</select>

<input type="submit" value="Submit"> <input type="reset">

</form>

</body>

</html>

Form.java

import java.io.IOException; import java.io.PrintWriter; import


javax.servlet.ServletException; import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;
@WebServlet("/MyForm") public

class Form extends HttpServlet


{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException

{
String em = request.getParameter("email");
String un = request.getParameter("uname");
String pa = request.getParameter("pass"); String ge =
request.getParameter("gender"); String co =
request.getParameter("Course");
response.setContentType("text/html");
PrintWriter pw=response.getWriter();

pw.write("<h2> Following data received sucessfully.. <h2> <br>"); pw.write("<h3> Email: "+
em +" </h3>");
pw.write("<h3> User name: "+ un +" </h3>"); pw.write("<h3> Password:
"+ pa +" </h3>"); pw.write("<h3> Gender: "+ ge +" </h3>");
pw.write("<h3> Course: "+ co +" </h3> "); pw.write("</h3>");

Output:
2. Develop a program to receive student subject marks through HTML forms
TextField and send the response as passed or Failed in Examination.

CODE:-

Form.java

import java.io.IOException; import


java.io.PrintWriter;

import javax.servlet.ServletException; import


javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest; import


javax.servlet.http.HttpServletResponse; public class logs
extends HttpServlet

public void doGet(HttpServletRequest req, HttpServletResponse res) throws


IOException, ServletException

{
PrintWriter pw = res.getWriter(); res.setContentType("text/html");

String name = req.getParameter("name"); String


marks = req.getParameter("marks"); int m =
Integer.parseInt(marks); if(m>=80)
{ pw.println("Passed");

}
else{ pw.println("Failed");

}
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws
IOException, ServletException

doGet(req,res); } }
index.html
<!DOCTYPE html>
<html>
<body>
<form action="Form">
Enter the name:<input type ="text" name ="name">
Enter the marks:<input type ="text" name ="marks">
<input type="submit" value="Enter">
</select>
</form>
</body>
</html>

Output:

You might also like