0% found this document useful (0 votes)
32 views12 pages

AJP Practical 18,20,22 OUTPUTS

Uploaded by

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

AJP Practical 18,20,22 OUTPUTS

Uploaded by

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

Output:

Page |
Output:

Page |
Grade and C (4M) P (4M) A (2M) Total ( 10 M) Dated Sign
Dated
Signature of
Teacher

Page |
116
Output:

Program Code:
1.Write a program to delete a record from a table. Ans

import java.sql.*; class


demojdbc {
public static void main(String args[]) { try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/data", "root", "");
Statement stmt = con.createStatement();
int rs = 0; try {
rs = stmt.executeUpdate(" delete from students where id= 1234");
System.out.println("Record Deleted");
} catch (SQLException throwables)
{
throwables.printStackTrace();
}
} catch (Exception e) {

Page |
System.out.println(e);
}
}
}

Output:

Page |
Exercise
1. Develop servlet program to retrieve data from List and Radio Button using
HTML Forms. Ans

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
Welcome
<br>
<br>
<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

Page
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:

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

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
{

Page |
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:

Page |
Program code
Write the output of following code considering below HTML is front end and
servlet as back end. Ans index.html

<html>
<body> <form
action="
http://localhost:8080/examples/servlets/servlet/AthonticationServlet”
method=”POST”>
User Name:<input type="text" name="username"><br>
Password:<input type="password" name="password" ><br>
<input type="submit">
</form>
</body>
</html>
AthonticationServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import
javax.servlet.ServletExcepti
on; import

Page |
javax.servlet.http.HttpServl
et; import
javax.servlet.http.HttpServl
etRequest; import
javax.servlet.http.HttpServl
etResponse;
public class AthonticationServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String pass="abhishek12345"; String
username,password;
username=request.getParameter("username");
password=request.getParameter("password"); if(username.equals(username)
&& password.equals(pass))
{
out.println("Login Successfull");
}
else
{
out.println("Login Unsuccessfull");
}
}
}
Output:

Page |
Page |

You might also like