首页 > 代码库 > JSP留言板
JSP留言板
删除 Delservlet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String id=request.getParameter("id"); LyBean lb =new LyBean(); lb.setId(id); lb.delete(); out.print("<script>window.location=‘admin.jsp‘<script>"); }
登录 Dlservlet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String yhm =request.getParameter("yhm"); if(yhm.equals("admin")) response.sendRedirect("admin.jsp"); else response.sendRedirect("liuyan.jsp"); }
留言 Lyservlet
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); response.setCharacterEncoding("gb2312"); PrintWriter out = response.getWriter(); request.setCharacterEncoding("gb2312"); String lyz = request.getParameter("lyz"); String xx = request.getParameter("xx"); LyBean lb =new LyBean(); lb.setLyz(lyz); lb.setXx(xx); lb.save(); out.print("<script>alert(‘保存成功‘);history.back();</script>"); out.flush(); out.close(); }
LyBean
import java.sql.*;public class LyBean { private String lyz; private String xx; private String id; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getLyz() { return lyz; } public void setLyz(String lyz) { this.lyz = lyz; } public String getXx() { return xx; } public void setXx(String xx) { this.xx = xx; } public void save(){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:db1"; Connection conn = DriverManager.getConnection(url, "", ""); Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.executeUpdate("insert into lyb(lyz,xx) values(‘"+ lyz +"‘,‘"+ xx +"‘)"); stmt.close(); conn.close(); } catch(Exception e){ e.printStackTrace(); } } public void delete(){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:db1"; Connection conn = DriverManager.getConnection(url, "", ""); Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.executeUpdate("delete from lyb where id="+id); stmt.close(); conn.close(); } catch(Exception e){ e.printStackTrace(); } }}
Admin.jsp
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="gb2312"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="http://www.mamicode.com/"> <title>My JSP ‘admin.jsp‘ starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="http://www.mamicode.com/styles.css"> --> </head> <body> <h1>留言信息</h1> <table border="1"> <tr> <td>留言者</td> <td>信息</td> <td>时间</td> <td>操作</td> </tr> <% try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:db1"; Connection conn = DriverManager.getConnection(url, "", ""); Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery("select * from lyb"); while(rs.next()){ %> <tr> <td><%=rs.getString("lyz")%></td> <td><%=rs.getString("xx")%></td> <td><%=rs.getString("rq")%></td> <td><a href=http://www.mamicode.com/delservlet?id=<%=rs.getString("id") %>>删除</a></td> </tr> <% } stmt.close(); conn.close(); } catch(Exception e){ e.printStackTrace(); } %> </table> </body></html>
JSP留言板
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。