JSP第十一次作业
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="images/sms_unReaded.png" /> <% 46 } else { 47 %> <img src="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>
查看,阅读状态改变
删除
回复: