1. 程式人生 > 遊戲攻略 >《原神攻略》薄荷採集地點整理

《原神攻略》薄荷採集地點整理

1.建庫,建表2個
使用者表(id,使用者名稱,密碼)
郵件表(id,發件人,收件人,標題,內容,傳送時間,狀態)

2.建model層
entity,dao包

3.登陸,註冊,登陸後顯示全部郵件

 1 package com.cui.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 12 protected static Connection getConnection(){ 13 Connection conn=null; 14 try { 15 Class.forName("com.mysql.jdbc.Driver"); 16 conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/email?useUnicode=true&characterEncoding=utf8","root","123456");
17 System.out.println(conn); 18 19 } catch (Exception e) { 20 // TODO Auto-generated catch block 21 e.printStackTrace(); 22 } 23 return conn; 24 25 26 } 27 28 29 30 protected void closeall(Connection con,PreparedStatement ps,ResultSet rs){
31 try { 32 if(rs!=null){rs.close();} 33 if(ps!=null){ps.close();} 34 if(con!=null){con.close();} 35 } catch (SQLException e) { 36 // TODO Auto-generated catch block 37 e.printStackTrace(); 38 } 39 40 } 41 }
 1 package com.cui.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.List;
 9 
10 import com.cui.entity.message;
11 
12 
13 public class messagedao extends basedao{
14     public List<message> getAll(String uname){
15         List<message>list=new ArrayList<message>();
16         Connection con=getConnection();
17         PreparedStatement pred=null;
18         ResultSet resultSet=null;
19         String sql="select * from email where receiver=?";
20         try {
21             pred=con.prepareStatement(sql);
22             pred.setString(1, uname);
23             resultSet=pred.executeQuery();
24             while(resultSet.next()){
25                 message email=new message();
26                 email.setMid(resultSet.getInt(1));
27                 email.setUsername(resultSet.getString(2));
28                 email.setReceiver(resultSet.getString(3));
29                 email.setTitle(resultSet.getString(4));
30                 email.setText(resultSet.getString(5));
31                 email.setSendtime(resultSet.getDate(6));
32                 email.setState(resultSet.getInt(7));
33                 list.add(email);
34             }
35         } catch (SQLException e) {
36             
37             e.printStackTrace();
38         }
39         return list;
40     }
41 }
 1 package com.cui.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                 
16                 ResultSet rs=null;
17                 try {
18                      ps= conn.prepareStatement(sql);
19                     ps.setString(1, uname);
20                     ps.setString(2, upwd);
21                     rs=ps.executeQuery();
22                     while(rs.next()){
23                         f=true;
24                     }
25                     
26                 } catch (SQLException e) {
27                     // TODO Auto-generated catch block
28                     e.printStackTrace();
29                     
30                 } finally{
31                     closeall(conn, ps, rs);
32                 }
33                 return f;
34             }
35     public int register(String uname,String upwd){
36         int i=-1;
37         Connection con=basedao.getConnection();
38         String sql="insert into users(uname,upwd)values(?,?)";
39         PreparedStatement pred = null;
40         try {
41             pred=con.prepareStatement(sql);
42             pred.setString(1, uname);
43             pred.setString(2, upwd);
44             i =pred.executeUpdate();
45             
46         } catch (SQLException e) {
47             // TODO Auto-generated catch block
48             e.printStackTrace();
49         }finally{
50             closeall(con, pred, null);
51         }
52         return i;
53         
54         
55     }
56 }
 1 package com.cui.entity;
 2 
 3 import java.sql.Date;
 4 
 5 public class message {
 6     private int mid;            //編號
 7     private String username;    //發件人姓名
 8     private String receiver;    //收件人姓名
 9     private String title;       //標題
10     private String text;        //內容
11     private Date sendtime;      //傳送時間
12     private int state;          //狀態
13     public int getMid() {
14         return mid;
15     }
16     public void setMid(int mid) {
17         this.mid = mid;
18     }
19     public String getUsername() {
20         return username;
21     }
22     public void setUsername(String username) {
23         this.username = username;
24     }
25     public String getReceiver() {
26         return receiver;
27     }
28     public void setReceiver(String receiver) {
29         this.receiver = receiver;
30     }
31     public String getTitle() {
32         return title;
33     }
34     public void setTitle(String title) {
35         this.title = title;
36     }
37     public String getText() {
38         return text;
39     }
40     public void setText(String text) {
41         this.text = text;
42     }
43     public Date getSendtime() {
44         return sendtime;
45     }
46     public void setSendtime(Date sendtime) {
47         this.sendtime = sendtime;
48     }
49     public int getState() {
50         return state;
51     }
52     public void setState(int state) {
53         this.state = state;
54     }
55     
56     
57 
58 }
 1 package com.cui.entity;
 2 
 3 public class users {
 4     private int uid;           //編號
 5     private String uname;      //賬號
 6     private String upwd;       //密碼
 7     public int getUid() {
 8         return uid;
 9     }
10     public void setUid(int uid) {
11         this.uid = uid;
12     }
13     public String getUname() {
14         return uname;
15     }
16     public void setUname(String uname) {
17         this.uname = uname;
18     }
19     public String getUpwd() {
20         return upwd;
21     }
22     public void setUpwd(String upwd) {
23         this.upwd = upwd;
24     }
25     
26 }
 1 <%@page import="com.cui.dao.messagedao"%>
 2 <%@page import="com.cui.dao.usersdao"%>
 3 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 4 
 5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 6 <html>
 7   <head> </head>
 8   
 9   <body>
10 <% 
11 String uname=request.getParameter("uname");
12 String upwd=request.getParameter("upwd");
13 usersdao ud=new usersdao();
14 if(ud.login(uname, upwd)){
15 session.setAttribute("uname", uname);
16 request.getRequestDispatcher("main.jsp").forward(request,response);
17 }else{
18 out.print("登陸失敗,三秒後返回登入介面");
19 response.setHeader("refresh", "3;url=login.jsp");
20 }
21 
22 
23 %>
24  </body>
25 </html>
 1 <%@page import="com.cui.dao.messagedao"%>
 2 <%@page import="com.cui.dao.usersdao"%>
 3 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 4 
 5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 6 <html>
 7   <head> </head>
 8   
 9   <body>
10 <% 
11 String uname=request.getParameter("uname");
12 String upwd=request.getParameter("upwd");
13 usersdao ud=new usersdao();
14 if(ud.login(uname, upwd)){
15 session.setAttribute("uname", uname);
16 request.getRequestDispatcher("main.jsp").forward(request,response);
17 }else{
18 out.print("登陸失敗,三秒後返回登入介面");
19 response.setHeader("refresh", "3;url=login.jsp");
20 }
21 
22 
23 %>
24  </body>
25 </html>
 1 <%@page import="com.cui.dao.usersdao"%>
 2 <%@page import="javax.xml.bind.ParseConversionEvent"%>
 3 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 4 
 5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 6 <html>
 7   <head>
 8   </head>
 9   
10   <body>
11     <%
12         String uname = request.getParameter("uname");
13         String upwd = request.getParameter("upwd");
14         usersdao u=new usersdao();
15         int i=u.register(uname, upwd);
16         if (i > 0) {
17             out.print("註冊成功,三秒後返回登入介面");
18             response.setHeader("refresh", "3;url=login.jsp");
19         } else {
20             out.print("註冊失敗,三秒後返回註冊介面");
21             response.setHeader("refresh", "3;url=register.jsp");
22         }
23     %>
24   </body>
25 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
 2 <%
 3 String path = request.getContextPath();
 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 5 %>
 6 
 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 8 <html>
 9   <head>
10     <base href="<%=basePath%>">
11     
12     <title>My JSP 'index.jsp' starting page</title>
13     <meta http-equiv="pragma" content="no-cache">
14     <meta http-equiv="cache-control" content="no-cache">
15     <meta http-equiv="expires" content="0">    
16     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
17     <meta http-equiv="description" content="This is my page">
18     <!--
19     <link rel="stylesheet" type="text/css" href="styles.css">
20     -->
21   </head>
22   
23   <body>
24     This is my JSP page. <br>
25   </body>
26 </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> </head>
 6   
 7   <body>
 8   <form action="dologin.jsp" method="post">
 9     賬號:<input type="text" name="uname" ><br>
10     密碼:<input type="upwd" name="upwd" ><br>
11     <input type="submit" value=登入>
12     <a href="register.jsp" >註冊</a>
13 
14     </form>
15   </body>
16 </html>
 1 <%@page import="com.cui.entity.message"%>
 2 <%@page import="com.cui.dao.messagedao"%>
 3 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 5 <html>
 6   <head> </head>
 7   <body>
 8   <% 
 9   messagedao md=new messagedao();
10   String name=(String)session.getAttribute("uname");
11   List<message> list=md.getAll(name);%>
12   歡迎你<%=name %> 
13   <table>
14   <tr><td>編號</td>
15   <td>發件人</td>
16   <td>收件人</td>
17   <td>標題</td>
18   <td>內容</td>
19   <td>傳送時間</td>
20   <td>狀態</td>
21   </tr>
22   <%for(int i=0;i<list.size();i++){%>
23       <tr><td><%out.print(list.get(i).getMid());%></td>
24        <td><%out.print(list.get(i).getUsername());%></td>
25        <td><% out.print(list.get(i).getReceiver());%></td>
26         <td><%out.print(list.get(i).getTitle());%></td>
27          <td><% out.print(list.get(i).getText());%></td>
28           <td><% out.print(list.get(i).getSendtime());%></td>
29           <td><%  out.print(list.get(i).getState());%></td></tr>
30   <%}%>
31    </table>
32   </body>
33 </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> </head>
 6   
 7   <body>
 8  <form action="doregister.jsp" method="post">
 9  賬號:<input type="text" name="uname"><br>
10  密碼:<input type="text" name="upwd"><br>
11 <input type="submit"value="註冊">
12 <input type="reset" value="重置 ">
13  </form>
14   </body>
15 </html>