1.第十二周上机作业(邮件功能)的控制层代码改用为servlet实现。
2.学习通发布了考试,截止到本周六。

 com.gd.dao
 BaseDao
 1 package com.gd.dao;
2
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.PreparedStatement;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8
9 public class BaseDao {
10 //获取连接
11 protected Connection getConnection(){
12 Connection conn=null;
13 try {
14 Class.forName("com.mysql.jdbc.Driver");
15 // 2.建立连接
16 conn = DriverManager.getConnection(
17 "jdbc:mysql://localhost:3306/test", "root", "123456");
18 } catch (Exception e) {
19 e.printStackTrace();
20 }
21 return conn;
22 }
23 //关闭连接
24 protected void closeAll(Connection con,PreparedStatement ps,ResultSet rs){
25 try {
26 if(rs != null)
27 rs.close();
28 if(ps != null)
29 ps.close();
30 if(con != null)
31 con.close();
32
33 } catch (SQLException e) {
34 e.printStackTrace();
35 }
36 }
37
38 }

MsgDao

  1 package com.gd.dao;
2
3 import java.sql.Connection;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.util.ArrayList;
8 import java.util.Date;
9 import java.util.List;
10
11 import com.gd.entity.Msg;
12
13 public class MsgDao extends BaseDao {
14 //根据收件人查看全部邮件
15 public List<Msg> getMailByReceiver(String name){
16 List<Msg> list=new ArrayList<Msg>();
17 Connection con=getConnection();
18 String sql="select * from msg where sendto=?";
19 PreparedStatement ps=null;
20 ResultSet rs=null;
21 try {
22 ps = con.prepareStatement(sql);
23 ps.setString(1, name);
24 rs=ps.executeQuery();
25 while(rs.next()){
26 //每读取一行,创建一个msg对象,对象放到集合中
27 Msg m=new Msg();
28 m.setMsgid(rs.getInt(1));
29 m.setUsername(rs.getString(2));
30 m.setTitle(rs.getString(3));
31 m.setMsgcontent(rs.getString(4));
32 m.setState(rs.getInt(5));
33 m.setSendto(rs.getString(6));
34 m.setMsg_create_date(rs.getDate(7));
35 list.add(m);
36 }
37
38 } catch (SQLException e) {
39 // TODO Auto-generated catch block
40 e.printStackTrace();
41 }finally{
42 closeAll(con, ps, rs);
43 }
44 return list;
45 }
46 //关于邮件的增删改查
47 //添加邮件(写邮件,回复邮件都调用,邮件状态为1(未读),时间为系统当前时间)
48 public void addMsg(Msg m){
49 Connection conn=getConnection();
50 String sql="insert into msg(username,title,msgcontent,state,sendto,msg_create_date) values(?,?,?,1,?,?)";
51 PreparedStatement ps=null;
52 try {
53 ps=conn.prepareStatement(sql);
54 ps.setString(1, m.getUsername());
55 ps.setString(2, m.getTitle());
56 ps.setString(3, m.getMsgcontent());
57 ps.setString(4, m.getSendto());
58 ps.setDate(5, new java.sql.Date(new Date().getTime()));
59 ps.executeUpdate();
60 } catch (SQLException e) {
61 // TODO Auto-generated catch block
62 e.printStackTrace();
63 }finally{
64 closeAll(conn, ps, null);
65 }
66 }
67
68 //根据id删除邮件
69 public void delMsg(int id){
70 Connection con=getConnection();
71 String sql="delete from msg where msgid="+id;
72 PreparedStatement ps=null;
73 try {
74 ps=con.prepareStatement(sql);
75 ps.executeUpdate();
76 } catch (SQLException e) {
77 // TODO Auto-generated catch block
78 e.printStackTrace();
79 }finally{
80 closeAll(con, ps, null);
81 }
82 }
83 public void updateMsg(int id) {
84 Connection con = getConnection();
85 String sql = "update msg set state='0' where msgid=?";
86 PreparedStatement pred = null;
87 try {
88 pred = con.prepareStatement(sql);
89 pred.setInt(1, id);
90 pred.executeUpdate();
91 } catch (SQLException e1) {
92 e1.printStackTrace();
93 } finally {
94 closeAll(con, pred, null);
95 }
96 }
97
98 public Msg read(int id) {
99 Connection con = getConnection();
100 String sql = "select msgid,username,sendto,title,msgcontent,msg_create_date from msg where msgid=?";
101 PreparedStatement ps = null;
102 ResultSet rs = null;
103 try {
104 ps = con.prepareStatement(sql);
105 ps.setInt(1, id);
106 rs = ps.executeQuery();
107 while (rs.next()) {
108 Msg m = new Msg();
109 m.setMsgid(rs.getInt("msgid"));
110 m.setUsername(rs.getString("username"));
111 m.setTitle(rs.getString("title"));
112 m.setMsgcontent(rs.getString("msgcontent"));
113 m.setSendto(rs.getString("sendto"));
114 m.setMsg_create_date(rs.getDate("msg_create_date"));
115 return m;
116 }
117
118 } catch (SQLException e) {
119 e.printStackTrace();
120 } finally {
121 closeAll(con, ps, rs);
122 }
123 return null;
124 }
125 }

UsersDao

 1 package com.gd.dao;
2
3 import java.sql.Connection;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7
8 public class UsersDao extends BaseDao {
9 // 登陆
10 public boolean login(String uname, String upwd) {
11 boolean f = false;
12 Connection conn = getConnection();
13 String sql = "select * from users where uname=? and upwd=?";
14 PreparedStatement ps = null;
15 ResultSet rs = null;
16 try {
17 ps = conn.prepareStatement(sql);
18 ps.setString(1, uname);// 第一个?赋值为name
19 ps.setString(2, upwd);
20 rs = ps.executeQuery();
21 if (rs.next())// 查到结果了
22 f = true;
23 } catch (SQLException e) {
24 // TODO Auto-generated catch block
25 e.printStackTrace();
26 } finally {
27 closeAll(conn, ps, rs);
28 }
29 return f;
30 }
31 // 注册
32 public int reg(String uname,String upwd){
33 int i=-1;
34 PreparedStatement pred=null;
35 Connection con=getConnection();
36 String sql="insert into users(uname,upwd)values(?,?)";
37 try {
38 pred= con.prepareStatement(sql);
39 pred.setString(1, uname);
40 pred.setString(2, upwd);
41 i=pred.executeUpdate();
42 } catch (SQLException e) {
43 e.printStackTrace();
44 }finally{
45 closeAll(con, pred, null);
46 }
47 return i;
48 }
49 }

com.gd.entity

Msg

 1 package com.gd.entity;
2
3 import java.util.Date;
4
5 public class Msg {
6 private Integer msgid;
7 private String username;
8 private String title;
9 private String msgcontent;
10 private int state;
11 private String sendto;
12 private Date msg_create_date;
13
14 public Msg() {
15 super();
16 // TODO Auto-generated constructor stub
17 }
18
19 public Msg(Integer msgid, String username, String title, String msgcontent,
20 int state, String sendto, Date msg_create_date) {
21 super();
22 this.msgid = msgid;
23 this.username = username;
24 this.title = title;
25 this.msgcontent = msgcontent;
26 this.state = state;
27 this.sendto = sendto;
28 this.msg_create_date = msg_create_date;
29 }
30
31 public Integer getMsgid() {
32 return msgid;
33 }
34
35 public void setMsgid(Integer msgid) {
36 this.msgid = msgid;
37 }
38
39 public String getUsername() {
40 return username;
41 }
42
43 public void setUsername(String username) {
44 this.username = username;
45 }
46
47 public String getTitle() {
48 return title;
49 }
50
51 public void setTitle(String title) {
52 this.title = title;
53 }
54
55 public String getMsgcontent() {
56 return msgcontent;
57 }
58
59 public void setMsgcontent(String msgcontent) {
60 this.msgcontent = msgcontent;
61 }
62
63 public int getState() {
64 return state;
65 }
66
67 public void setState(int state) {
68 this.state = state;
69 }
70
71 public String getSendto() {
72 return sendto;
73 }
74
75 public void setSendto(String sendto) {
76 this.sendto = sendto;
77 }
78
79 public Date getMsg_create_date() {
80 return msg_create_date;
81 }
82
83 public void setMsg_create_date(Date msg_create_date) {
84 this.msg_create_date = msg_create_date;
85 }
86
87
88 }

Users:

 1 package com.gd.entity;
2
3 public class Users {
4 private Integer id;
5 private String uname;
6 private String upwd;
7
8 public Users() {
9 super();
10 // TODO Auto-generated constructor stub
11 }
12
13 public Users(Integer id, String uname, String upwd) {
14 super();
15 this.id = id;
16 this.uname = uname;
17 this.upwd = upwd;
18 }
19
20 public Integer getId() {
21 return id;
22 }
23
24 public void setId(Integer id) {
25 this.id = id;
26 }
27
28 public String getUname() {
29 return uname;
30 }
31
32 public void setUname(String uname) {
33 this.uname = uname;
34 }
35
36 public String getUpwd() {
37 return upwd;
38 }
39
40 public void setUpwd(String upwd) {
41 this.upwd = upwd;
42 }
43
44 }

com.gd.servlet

RegServlet

 1 package com.gd.servlet;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5
6 import javax.servlet.ServletException;
7 import javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10
11 import com.gd.dao.UsersDao;
12
13 public class RegServlet extends HttpServlet {
14
15 /**
16 * Constructor of the object.
17 */
18 public RegServlet() {
19 super();
20 }
21
22 /**
23 * Destruction of the servlet. <br>
24 */
25 public void destroy() {
26 super.destroy(); // Just puts "destroy" string in log
27 // Put your code here
28 }
29
30 /**
31 * The doGet method of the servlet. <br>
32 *
33 * This method is called when a form has its tag value method equals to get.
34 *
35 * @param request
36 * the request send by the client to the server
37 * @param response
38 * the response send by the server to the client
39 * @throws ServletException
40 * if an error occurred
41 * @throws IOException
42 * if an error occurred
43 */
44 public void doGet(HttpServletRequest request, HttpServletResponse response)
45 throws ServletException, IOException {
46
47 doPost(request, response);
48 }
49
50 /**
51 * The doPost method of the servlet. <br>
52 *
53 * This method is called when a form has its tag value method equals to
54 * post.
55 *
56 * @param request
57 * the request send by the client to the server
58 * @param response
59 * the response send by the server to the client
60 * @throws ServletException
61 * if an error occurred
62 * @throws IOException
63 * if an error occurred
64 */
65 public void doPost(HttpServletRequest request, HttpServletResponse response)
66 throws ServletException, IOException {
67 request.setCharacterEncoding("utf-8");
68 response.setCharacterEncoding("utf-8");
69 response.setContentType("text/html;charset=utf-8");
70 PrintWriter out = response.getWriter();
71 String uname = request.getParameter("uname");
72 String upwd = request.getParameter("upwd");
73 UsersDao ud = new UsersDao();
74 int i = ud.reg(uname, upwd);
75 if (i > 0) {
76 out.print("注册成功,即将跳到登录页.....");
77 response.setHeader("refresh", "2;url=denglu.jsp");
78 } else {
79 out.print("注册失败,即将跳回注册页.....");
80 response.setHeader("refresh", "2;url=reg.jsp");
81 }
82 }
83
84 /**
85 * Initialization of the servlet. <br>
86 *
87 * @throws ServletException
88 * if an error occurs
89 */
90 public void init() throws ServletException {
91 // Put your code here
92 }
93
94 }

LoginServlet

 1 package com.gd.servlet;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5
6 import javax.servlet.ServletException;
7 import javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10 import javax.servlet.http.HttpSession;
11
12 import com.gd.dao.UsersDao;
13
14 public class LoginServlet extends HttpServlet {
15
16 /**
17 * Constructor of the object.
18 */
19 public LoginServlet() {
20 super();
21 }
22
23 /**
24 * Destruction of the servlet. <br>
25 */
26 public void destroy() {
27 super.destroy(); // Just puts "destroy" string in log
28 // Put your code here
29 }
30
31 /**
32 * The doGet method of the servlet. <br>
33 *
34 * This method is called when a form has its tag value method equals to get.
35 *
36 * @param request the request send by the client to the server
37 * @param response the response send by the server to the client
38 * @throws ServletException if an error occurred
39 * @throws IOException if an error occurred
40 */
41 public void doGet(HttpServletRequest request, HttpServletResponse response)
42 throws ServletException, IOException {
43
44 doPost(request, response);
45 }
46
47 /**
48 * The doPost method of the servlet. <br>
49 *
50 * This method is called when a form has its tag value method equals to post.
51 *
52 * @param request the request send by the client to the server
53 * @param response the response send by the server to the client
54 * @throws ServletException if an error occurred
55 * @throws IOException if an error occurred
56 */
57 public void doPost(HttpServletRequest request, HttpServletResponse response)
58 throws ServletException, IOException {
59 response.setContentType("text/html;charset=utf-8");
60 HttpSession session=request.getSession();
61 PrintWriter out = response.getWriter();
62 request.setCharacterEncoding("utf-8");
63 response.setCharacterEncoding("utf-8");
64 String uname = request.getParameter("uname");
65 String upwd = request.getParameter("upwd");
66 UsersDao ud = new UsersDao();
67 if (ud.login(uname, upwd)) {
68 session.setAttribute("uname", uname);
69 request.getRequestDispatcher("main.jsp").forward(request,
70 response);
71 } else {
72 out.print("登录失败,即将跳回登录页.....");
73 response.setHeader("refresh", "5;url=denglu.jsp");
74 }
75
76 }
77
78 /**
79 * Initialization of the servlet. <br>
80 *
81 * @throws ServletException if an error occurs
82 */
83 public void init() throws ServletException {
84 // Put your code here
85 }
86
87 }

WriteServlet

 1 package com.gd.servlet;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5
6 import javax.servlet.ServletException;
7 import javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10 import javax.servlet.http.HttpSession;
11
12 import com.gd.dao.MsgDao;
13 import com.gd.entity.Msg;
14
15 public class WriteServlet extends HttpServlet {
16
17 /**
18 * Constructor of the object.
19 */
20 public WriteServlet() {
21 super();
22 }
23
24 /**
25 * Destruction of the servlet. <br>
26 */
27 public void destroy() {
28 super.destroy(); // Just puts "destroy" string in log
29 // Put your code here
30 }
31
32 /**
33 * The doGet method of the servlet. <br>
34 *
35 * This method is called when a form has its tag value method equals to get.
36 *
37 * @param request the request send by the client to the server
38 * @param response the response send by the server to the client
39 * @throws ServletException if an error occurred
40 * @throws IOException if an error occurred
41 */
42 public void doGet(HttpServletRequest request, HttpServletResponse response)
43 throws ServletException, IOException {
44
45 doPost(request, response);
46 }
47
48 /**
49 * The doPost method of the servlet. <br>
50 *
51 * This method is called when a form has its tag value method equals to post.
52 *
53 * @param request the request send by the client to the server
54 * @param response the response send by the server to the client
55 * @throws ServletException if an error occurred
56 * @throws IOException if an error occurred
57 */
58 public void doPost(HttpServletRequest request, HttpServletResponse response)
59 throws ServletException, IOException {
60
61 response.setContentType("text/html;charset=utf-8");
62 PrintWriter out = response.getWriter();
63 request.setCharacterEncoding("utf-8");
64 response.setCharacterEncoding("utf-8");
65 HttpSession session=request.getSession();
66
67 String uname=(String)session.getAttribute("uname");// 发件人在session中获取
68 String sendto=request.getParameter("sendto");
69 String title=request.getParameter("title");
70 String content=request.getParameter("content");
71
72 Msg m=new Msg();
73 m.setTitle(title);
74 m.setMsgcontent(content);
75 m.setUsername(uname);
76 m.setSendto(sendto);
77
78 MsgDao md=new MsgDao();
79 md.addMsg(m);
80
81 out.print("发送成功,即将跳回首页.....");
82 response.setHeader("refresh", "3;url=main.jsp");
83 }
84
85 /**
86 * Initialization of the servlet. <br>
87 *
88 * @throws ServletException if an error occurs
89 */
90 public void init() throws ServletException {
91 // Put your code here
92 }
93
94 }

AnswerServlet

 1 package com.gd.servlet;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5
6 import javax.servlet.ServletException;
7 import javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10
11 import com.gd.dao.MsgDao;
12 import com.gd.entity.Msg;
13
14 public class AnswerServlet extends HttpServlet {
15
16 /**
17 * Constructor of the object.
18 */
19 public AnswerServlet() {
20 super();
21 }
22
23 /**
24 * Destruction of the servlet. <br>
25 */
26 public void destroy() {
27 super.destroy(); // Just puts "destroy" string in log
28 // Put your code here
29 }
30
31 /**
32 * The doGet method of the servlet. <br>
33 *
34 * This method is called when a form has its tag value method equals to get.
35 *
36 * @param request the request send by the client to the server
37 * @param response the response send by the server to the client
38 * @throws ServletException if an error occurred
39 * @throws IOException if an error occurred
40 */
41 public void doGet(HttpServletRequest request, HttpServletResponse response)
42 throws ServletException, IOException {
43
44 doPost(request,response);
45 }
46
47 /**
48 * The doPost method of the servlet. <br>
49 *
50 * This method is called when a form has its tag value method equals to post.
51 *
52 * @param request the request send by the client to the server
53 * @param response the response send by the server to the client
54 * @throws ServletException if an error occurred
55 * @throws IOException if an error occurred
56 */
57 public void doPost(HttpServletRequest request, HttpServletResponse response)
58 throws ServletException, IOException {
59
60 response.setContentType("text/html;charset=utf-8");
61 PrintWriter out = response.getWriter();
62 request.setCharacterEncoding("utf-8");
63 response.setCharacterEncoding("utf-8");
64
65 String uname=request.getParameter("rely");
66 String sendto=request.getParameter("sendto");
67 String title=request.getParameter("title");
68 String content=request.getParameter("content");
69
70 Msg m=new Msg();
71 m.setTitle(title);
72 m.setMsgcontent(content);
73 m.setUsername(uname);
74 m.setSendto(sendto);
75
76 MsgDao md=new MsgDao();
77 md.addMsg(m);
78
79 out.print("发送成功,即将跳回首页.....");
80 response.setHeader("refresh", "3;url=main.jsp");
81
82 }
83
84 /**
85 * Initialization of the servlet. <br>
86 *
87 * @throws ServletException if an error occurs
88 */
89 public void init() throws ServletException {
90 // Put your code here
91 }
92
93 }

jsp

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3 <html>
4 <head>
5 <title>My JSP 'reg.jsp' starting page</title>
6 </head>
7
8 <body>
9 <h1>注册</h1>
10 <script>
11 function yz() {
12 if (form.uname.value == "") {
13 alert('用户名不能为空');
14 return;
15 }
16 if (form.upwd.value == "") {
17 alert('密码不能为空');
18 return;
19 }
20 form.submit();
21 }
22 </script>
23 <form action="RegServlet" method="post" name="form">
24 <table>
25 <tr>
26 <td>用户名</td>
27 <td><input type="text" name="uname"></td>
28 </tr>
29 <tr>
30 <td>密码</td>
31 <td><input type="password" name="upwd" value="123456"></td>
32 </tr>
33 <tr>
34 <td><input type="button" value="注册" onclick="yz()"></td>
35 <td><a href="denglu.jsp">登录</a></td>
36 </tr>
37 </table>
38 </form>
39 </body>
40 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3 <html>
4 <head>
5 <title>My JSP 'denglu.jsp' starting page</title>
6 </head>
7
8 <body>
9 <h1>登录</h1>
10 <script type="text/javascript">
11 function validate() {
12 if (loginForm.uname.value == "") {
13 alert("账号不能为空!");
14 return;
15 }
16 if (loginForm.upwd.value == "") {
17 alert("密码不能为空!");
18 return;
19 }
20 loginForm.submit();
21 }
22 </script>
23 <form action="LoginServlet" method="post" name="loginForm">
24 <table>
25 <tr>
26 <td>用户名</td>
27 <td><input type="text" name="uname"></td>
28 </tr>
29 <tr>
30 <td>密码</td>
31 <td><input type="password" name="upwd" value="123456"></td>
32 </tr>
33 <tr>
34 <td><input type="button" value="登录" onClick="validate()"></td>
35 <td><a href="reg.jsp">立即注册</a></td>
36 </tr>
37 </table>
38 </form>
39
40 </body>
41 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%@page import="com.gd.entity.Msg"%>
3 <%@page import="com.gd.dao.MsgDao"%>
4 <%
5 request.setCharacterEncoding("utf-8");
6 response.setCharacterEncoding("utf-8");
7 %>
8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
9 <html>
10 <head>
11 <title>My JSP 'main.jsp' starting page</title>
12 </head>
13 <body>
14 <%
15 MsgDao md = new MsgDao();
16 String uname = (String) session.getAttribute("uname");
17 List<Msg> list = md.getMailByReceiver(uname);
18 %>
19 欢迎你<%=uname%>
20 <a href="write.jsp">写邮件</a>
21 <a href="exit.jsp">退出登录</a>
22 <table border="1">
23 <tr>
24 <td>发件人</td>
25 <td>主题</td>
26 <td>状态</td>
27 <td>时间</td>
28 <td>操作</td>
29 <td>操作</td>
30 </tr>
31
32 <%
33 for (int i = 0; i < list.size(); i++) {
34 %>
35 <tr>
36 <td><%=list.get(i).getUsername()%></td>
37
38 <td><a href="detail.jsp?id=<%=list.get(i).getMsgid()%>">
39 <%out.print(list.get(i).getTitle().toString());%>
40 </a>
41 </td>
42 <td>
43 <%
44 if (list.get(i).getState() == 1) {
45 %> <img src="data:images/sms_unReaded.png" /> <%
46 } else {
47 %> <img src="data:images/sms_readed.png" /> <%
48 }
49 %>
50 </td>
51 <td><%=list.get(i).getMsg_create_date()%></td>
52 <td><a href="answer.jsp?rely=<%=list.get(i).getUsername()%>">回复</a>
53 </td>
54 <td><a href="del.jsp?id=<%=list.get(i).getMsgid()%>">删除</a>
55 </td>
56 </tr>
57 <%
58 }
59 %>
60 </table>
61
62 </body>
63 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%
3 request.setCharacterEncoding("utf-8");
4 response.setCharacterEncoding("utf-8");
5 %>
6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
7 <html>
8 <head>
9 <title>My JSP 'write.jsp' starting page</title>
10 </head>
11 <body>
12 <form action="WriteServlet" method="post" name="form">
13 <table>
14 <tr>
15 <td>收件人</td>
16 <td><input type="text" name="sendto">
17 </td>
18 </tr>
19 <tr>
20 <td>主题</td>
21 <td><input type="text" name="title">
22 </td>
23 </tr>
24 <tr>
25 <td>内容</td>
26 <td><textarea rows="6" cols="20" name="content"></textarea>
27 </td>
28 </tr>
29 <tr>
30 <td><input type="submit" value="发送">
31 </td>
32 </tr>
33 </table>
34 </form>
35 </body>
36 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%@page import="com.gd.dao.MsgDao"%>
3 <%@page import="com.gd.entity.Msg"%>
4 <%
5 request.setCharacterEncoding("utf-8");
6 response.setCharacterEncoding("utf-8");
7 %>
8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
9 <html>
10 <head>
11 <title>My JSP 'index.jsp' starting page</title>
12 </head>
13 <body>
14 <%
15 request.setCharacterEncoding("utf-8");
16 String msgid = request.getParameter("id");
17 int idd = Integer.parseInt(msgid);
18 MsgDao md = new MsgDao();
19 md.updateMsg(idd);
20 Msg m = md.read(idd);
21 %>
22 <table>
23 <tr>
24 <td>发件人:</td>
25 <td><input type="text" name="username" style="border: none"
26 value="<%=m.getUsername()%>"></td>
27 </tr>
28 <tr>
29 <td>主题:</td>
30 <td><input type="text" name="title" style="border: none"
31 value="<%=m.getTitle()%>"></td>
32 </tr>
33 <tr>
34 <td>时间:</td>
35 <td><input type="text" name="msg_create_date"
36 style="border: none" value="<%=m.getMsg_create_date()%>"></td>
37 </tr>
38 <tr>
39 <td>收件人:</td>
40 <td><input type="text" name="sendto" style="border: none"
41 value="<%=m.getSendto()%>"></td>
42 </tr>
43 <tr>
44 <td>内容:</td>
45 <td><div style="border: none;outline: none;overflow: inherit;">
46 <%=m.getMsgcontent()%></div></td>
47 </tr>
48 </table>
49 <a href="main.jsp">返回</a>
50 </body>
51 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%@page import="com.gd.entity.Msg"%>
3 <%@page import="com.gd.dao.MsgDao"%>
4 <%@page import="com.gd.dao.UsersDao"%>
5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
6 <html>
7 <head>
8 <title>My JSP 'del.jsp' starting page</title>
9 </head>
10 <body>
11 <%
12 request.setCharacterEncoding("utf-8");
13 int id=Integer.parseInt(request.getParameter("id"));
14 MsgDao md=new MsgDao();
15 md.delMsg(id);
16 out.print("删除成功、、、、、、、");
17 response.sendRedirect("main.jsp");
18 %>
19 </body>
20 </html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'answer.jsp' starting page</title>
</head>
<body>
<form action="AnswerServlet" method="post" name="form">
<table>
<tr>
<td>收件人</td>
<td><input type="text" name="sendto" value="<%=request.getParameter("rely") %>">
</td>
</tr>
<tr>
<td>主题</td>
<td><input type="text" name="title">
</td>
</tr>
<tr>
<td>内容</td>
<td><textarea rows="6" cols="20" name="content"></textarea>
</td>
</tr>
<tr>
<td><input type="submit" value="发送">
</td>
</tr>
</table>
</form>
</body>
</html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2
3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <html>
5 <head>
6 <title>My JSP 'exit.jsp' starting page</title>
7 </head>
8
9 <body>
10 <%
11 session.invalidate();
12 response.sendRedirect("denglu.jsp");
13 %>
14 </body>
15 </html>

查看,阅读状态改变

删除

回复:

搜索

复制

JSP第十一次作业的更多相关文章

  1. 2017-2018-2 20179205《网络攻防技术与实践》第十一周作业 SQL注入攻击与实践

    <网络攻防技术与实践>第十一周作业 SQL注入攻击与实践 1.研究缓冲区溢出的原理,至少针对两种数据库进行差异化研究 缓冲区溢出原理   在计算机内部,输入数据通常被存放在一个临时空间内, ...

  2. 第十三次作业——回归模型与房价预测&第十一次作业——sklearn中朴素贝叶斯模型及其应用&第七次作业——numpy统计分布显示

    第十三次作业——回归模型与房价预测 1. 导入boston房价数据集 2. 一元线性回归模型,建立一个变量与房价之间的预测模型,并图形化显示. 3. 多元线性回归模型,建立13个变量与房价之间的预测模 ...

  3. 福大软工 · 第十一次作业 - Alpha 事后诸葛亮(团队)

    福大软工·第十一次作业-Alpha事后诸葛亮 组长博客链接 本次作业博客链接 项目Postmortem 模板 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描 ...

  4. 2017-2018-2 1723《程序设计与数据结构》第十一周作业 & 实验三 & (总体)第三周结对编程 总结

    作业地址 第十一次作业:https://edu.cnblogs.com/campus/besti/CS-IMIS-1723/homework/1933 (作业界面已评分,可随时查看,如果对自己的评分有 ...

  5. 实验十一 团队作业7—团队项目设计完善&编码测试

    实验十一 团队作业7—团队项目设计完善&编码测试 实验时间 2018-6-8 Deadline: 2018-6-20 10:00,以团队随笔博文提交至班级博客的时间为准. 评分标准: 按时交 ...

  6. 软工 · 第十一次作业 - Alpha 事后诸葛亮(团队)

    软工 · 第十一次作业 - Alpha 事后诸葛亮(团队) 组长本次作业链接 现代软件工程 项目Postmortem 设想和目标 1.我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场 ...

  7. 第十一次作业 - Alpha 事后诸葛亮(团队)

    软工 · 第十一次作业 - Alpha 事后诸葛亮(团队) 组长本次作业链接 现代软件工程 项目Postmortem 设想和目标 1.我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场 ...

  8. 福大软工·第十一次作业-Alpha事后诸葛亮

    福大软工·第十一次作业-Alpha事后诸葛亮 组长博客链接 本次作业博客链接 项目Postmortem 模板 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描 ...

  9. 《Linux内核原理与设计》第十一周作业 ShellShock攻击实验

    <Linux内核原理与设计>第十一周作业 ShellShock攻击实验 分组: 和20179215袁琳完成实验及博客攥写 实验内容:   Bash中发现了一个严重漏洞shellshock, ...

  10. 实验十一 团队作业7:团队项目设计完善&编码

    实验十一 团队作业7:团队项目设计完善&编码 实验时间 2019-6-6 Deadline: 2019-6-12 10:00,以团队随笔博文提交至班级博客的时间为准. 评分标准: 按时交 – ...

随机推荐

  1. h5 websocket 断开重新连接

    最近的项目中使用ws 长连接来接收和发送消息, 直接上代码 import * as SockJS from "sockjs-client"; import Stomp from & ...

  2. .net 温故知新:【9】.NET日志记录 ILogger使用和原理

    日志 日志作为我们程序记录的"黑匣子"是不论什么系统都会使用到的,比如我们经常使用的log4net就是第三方日志记录提供程序.NET 支持使用各种内置和第三方日志记录提供程序的日志 ...

  3. 基于python的数学建模---洛伦兹线与数值解

    import numpy as np from scipy.integrate import odeint from mpl_toolkits.mplot3d import Axes3D import ...

  4. 论文解读(CDCL)《Cross-domain Contrastive Learning for Unsupervised Domain Adaptation》

    论文信息 论文标题:Cross-domain Contrastive Learning for Unsupervised Domain Adaptation论文作者:Rui Wang, Zuxuan ...

  5. day29 jQuery选择器 & jquery属性操作 & jquery DOM元素 操作与遍历

    简介 jQuery,顾名思义,就是javascript和query(查询),即辅助javascript开发的库,本质就是一个js文件: jQuery是一个js函数库,是目前全球范围内最流行.用的最多的 ...

  6. Linux 中的文件简单说明

    Linux 中的文件简单说明 作者:Grey 原文地址: 博客园:Linux 中的文件简单说明 CSDN:Linux 中的文件简单说明 说明 本文基于 CentOS 7 根目录(/)下文件夹主要作用 ...

  7. 重学c#系列——linq(1) [二十七]

    前言 简单介绍一下linq,linq很多人其实用的很熟练了,但是有些人不知道自己用的是linq. 正文 在介绍linq 之前,先介绍一下集合. public interface ICollection ...

  8. 创建并且配置win10系统虚拟机

    一.创建Windows10镜像 1.下载地址:https://www.microsoft.com/zh-cn/software-download/windows10 2.制作镜像 完成之后,会生成一个 ...

  9. 从一道CTF题学习python字节码到源码逆向

    概述: 该题来源为2022爱春秋冬季赛ezpython,难度不是很大刚好适合我这样的萌新入门 题目: 3 0 LOAD_CONST 1 (204) 3 LOAD_CONST 2 (141) 6 LOA ...

  10. vivo 游戏中心低代码平台的提效秘诀

    作者:vivo 互联网服务器团队- Chen Wenyang 本文根据陈文洋老师在"2022 vivo开发者大会"现场演讲内容整理而成.公众号回复[2022 VDC]获取互联网技术 ...