当前位置:编程学习 > JAVA >>

有一个用eclipse写的添加信息的动态网页,用了三个jsp和两个class,需要改成删除信息的,怎么办啊?急求

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="bbs.BaseConn"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="bbs.Topic"%>
<!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=UTF-8">
<title>帖子列表</title>
</head>
<%
Connection conn = BaseConn.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select id, title, username from topic");
ArrayList list = new ArrayList();
while(rs.next()){
Topic t = new Topic();
t.id = rs.getInt("id");
t.title = rs.getString("title");
t.username = rs.getString("username");
list.add(t);
}
request.setAttribute("list", list);
%>
<body>
<table align="center" width="600" height="600">
<tr>
<td colspan="3">
<h1>所有帖子的列表</h1>
</td>
</tr>
<tr>
<td>
序号
</td>
<td>
标题
</td>
<td>
发帖人
</td>
</tr>
<c:forEach items="${list}" var="t" varStatus="status">
<tr>
<td>
<c:out value="${t.id}"></c:out>
</td>
<td>
<c:out value="${t.title}"></c:out>
</td>
<td>
<c:out value="${t.username}"></c:out>
</td>
</tr>
</c:forEach>
<tr>
<td>
<a href="add.jsp">添加记录</a>
</td>
</tr>
</table>
</body>
</html>



result.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="bbs.BaseConn"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.PreparedStatement"%>
<!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=UTF-8">
<title>操作成功</title>
</head>
<%
Connection conn = BaseConn.getConnection();
String title = new String(request.getParameter("title").getBytes("ISO-8859-1"), "UTF-8");
String body = new String(request.getParameter("body").getBytes("ISO-8859-1"), "UTF-8");
String username = request.getParameter("username");

PreparedStatement pstmt = conn.prepareStatement("insert into topic (title, body, username) values (?, ?, ?)");
pstmt.setString(1, title);
pstmt.setString(2, body);
pstmt.setString(3, username);
pstmt.executeUpdate();
%>
<body>

add.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>添加记录</title>
</head>
<body>
<form action="result.jsp">
<table align="center" width="500" height="500">
<tr>
<td>
<h2>添加记录</h2>
</td>
</tr>
<tr>
<td>
标题: <input type="text" value="" name="title"></input>
</td>
</tr>
<tr>
<td>
正文: <textarea rows="20" cols="20" name="body"></textarea>
</td>
</tr>
<tr>
<td>
用户名: <input type="text" value="" name="username"></input>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交"></input>
</td>
</tr>
</table>
</form>
</body>
</html>


BaseConn.java
 
package bbs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class BaseConn {
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");// 加载数据库驱动
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbsdb?user=root&password=root");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
}



Topic.java

package bbs;

public class Topic {
public int id;
public String title;
public String body;
public String username;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
} --------------------编程问答-------------------- 学校作业吧? --------------------编程问答-------------------- 恩恩,谁能帮帮忙啊?!!!
补充:Java ,  Java SE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,