Reputation: 55
I developed a small web page which allows a user to register as a user and login. I have a admin login too wherein the admin can see all the users in the database and is able to delete or edit a user. So, I created two jsps one which is redirected when admin logs in and the other when he clicks delete. But due to some reason I am not getting directed to delete page from 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 * from 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 from Users where email=?");
ps.setString(1, name);
rs = ps.executeQuery();
%>
</body>
</html>
I am new to web programming so can someone let me know where I am doing wrong.
Upvotes: 0
Views: 194
Reputation: 680
You'll need to pass a value to delete.jsp (i.e. [email protected]) in admin.jsp and then in delete.jsp obtain this value using request.getParameter("email").
I don't have a way to test this, but you might also need to URL encode the email value, otherwise it might break your web application.
Upvotes: 1