step 1
Eclipse---File ----New----Dynamic Web Project----ProjectName----Finish
step 2
To Create a Jsp Page for delete.jsp
Click the Project Folder-----go to src folder----main folder----web app ---right click the web app---new
----jsp---delete.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="delete" method="post">
<input type="text" name="n1" placeholder="Username"><br><br>
<input type="submit"><br><br>
</form>
</body>
</html>
Create a Servlet Page
goto src/main/java then right click new---sevlet---class name---delete----finish
delete.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;
import java.sql.*;
/**
* Servlet implementation class register
*/
@WebServlet("/delete")
public class delete extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw=response.getWriter();
try
{
String a=request.getParameter("n1");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/example","root","");
Statement st=con.createStatement();
st.executeUpdate("delete from ex where username='"+a+"' ");
pw.println("delete successfully");
}
catch(Exception e)
{
pw.println(e);
}
}
}
connect the jar files
right click the project build path----configure build path---add external jars---add mysqlconnector.jar
Note : download the mysqlconnector.jar in google
also copy the jar file paste into ----src---main---web app---WEB-INF---lib-----mysql-connector.jar
Run
Right click the jsp page----run as ---run an server--finish
No comments:
Post a Comment