deleting rows from sql through jsp -


i developed small web page allows user register user , login. have admin login wherein admin can see users in database , able delete or edit user. so, created 2 jsps 1 redirected when admin logs in , other when clicks delete. due reason not getting directed delete page admin page.

admin.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page import="java.sql.*" import="com.javadbproject.util.dbconnectionmanager" import="javax.servlet.http.httpservlet"%> <%@ page language="java" contenttype="text/html; charset=us-ascii"          pageencoding="us-ascii"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=us-ascii">         <title>home page</title>          <link rel="stylesheet" type="text/css" href="<c:url value='/loginstyle.css'/>">       </head>     <body>         <%             preparedstatement ps = null;             resultset rs = null;               connection con = (connection) getservletcontext().getattribute("dbconnection");             ps = con.preparestatement("select * users");             rs = ps.executequery();             while (rs.next()) {         %>         <table><tr><td>name : <%=rs.getstring(1)%></td></tr>             <tr><td>email :<%=rs.getstring(2)%></td></tr>              <tr><td><a href = "delete.jsp">delete</a></td></tr>         </table>          <%             }             rs.close();             ps.close();             con.close();         %>         <form action="logout" method="post">             <input type="submit" value="logout" >          </form>     </body> </html> 

delete.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page import="java.sql.*" import="com.javadbproject.util.dbconnectionmanager"%> <%@ page language="java" contenttype="text/html; charset=us-ascii"          pageencoding="us-ascii"%> <!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <title>delete page</title>     </head>     <body>         <%             preparedstatement ps = null;             resultset rs = null;             connection con = (connection) getservletcontext().getattribute("dbconnection");             string name = rs.getstring(1);             ps = con.preparestatement("delete users email=?");             ps.setstring(1, name);             rs = ps.executequery();         %>     </body> </html> 

i new web programming can let me know doing wrong.

you'll need pass value delete.jsp (i.e. delete.jsp?email=test@gmail.com) in admin.jsp , in delete.jsp obtain value using request.getparameter("email").

i don't have way test this, might need url encode email value, otherwise might break web application.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -