jsp删除不了数据库里面的数据, 5
1.jsp页面<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%><%@taglibprefi...
1.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
table border="1">
<tr>
<td>账户</td>
<td>密码</td>
<td>用户名</td>
<td>时间</td>
<td>权限</td>
<td> </td>
</tr>
<c:forEach items="${list}" var="user">
<tr>
<td>${user.account}</td>
<td>${user.password}</td>
<td>${user.username}</td>
<td>${user.logintime}</td>
<td>${user.power}</td>
<td><a href="delServlet?account=${user.account }">删除</a></td>
</tr>
</c:forEach>
2.delServlet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String account= request.getParameter("account");
String sql = "delete from login where account = ' " + account + " ' ";
dengluDao dao= new dengluDao();
dao.executeDel(sql);
request.getRequestDispatcher("chaxunServlet").forward(request, response);
3.dao层
public void executeDel(String sql){
try {
conn = GetConnection.getConnection();
pstat = conn.prepareStatement(sql);
} catch (Exception e) {
System.out.println("statement取得错误");
System.out.println(e.getMessage());
}
try {
int rows = pstat.executeUpdate(sql);
if(rows >= 1){
System.out.println("成功删除.....");
} else {
System.out.println("删除失败.....");
}
} catch (Exception e) {
4.xml
<servlet>
<servlet-name>delServlet</servlet-name>
<servlet-class>servlet.delServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>delServlet</servlet-name>
<url-pattern>/delServlet</url-pattern>
</servlet-mapping> 展开
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
table border="1">
<tr>
<td>账户</td>
<td>密码</td>
<td>用户名</td>
<td>时间</td>
<td>权限</td>
<td> </td>
</tr>
<c:forEach items="${list}" var="user">
<tr>
<td>${user.account}</td>
<td>${user.password}</td>
<td>${user.username}</td>
<td>${user.logintime}</td>
<td>${user.power}</td>
<td><a href="delServlet?account=${user.account }">删除</a></td>
</tr>
</c:forEach>
2.delServlet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String account= request.getParameter("account");
String sql = "delete from login where account = ' " + account + " ' ";
dengluDao dao= new dengluDao();
dao.executeDel(sql);
request.getRequestDispatcher("chaxunServlet").forward(request, response);
3.dao层
public void executeDel(String sql){
try {
conn = GetConnection.getConnection();
pstat = conn.prepareStatement(sql);
} catch (Exception e) {
System.out.println("statement取得错误");
System.out.println(e.getMessage());
}
try {
int rows = pstat.executeUpdate(sql);
if(rows >= 1){
System.out.println("成功删除.....");
} else {
System.out.println("删除失败.....");
}
} catch (Exception e) {
4.xml
<servlet>
<servlet-name>delServlet</servlet-name>
<servlet-class>servlet.delServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>delServlet</servlet-name>
<url-pattern>/delServlet</url-pattern>
</servlet-mapping> 展开
3个回答
展开全部
追问
菜鸟一枚实在看不出哪里有错,求指教
追答
servlet里面你咋还写sql呢,所有sql写到dao里面去。servlet只用调用dao里面的方法就行了。自己看,例子
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询