5.2号团队冲刺(一)

5.2

燃尽图:

 任务板:

 

每日照片:

这是开始冲刺的第一天,我们打算先把数据库创建起来,根据我们的需要,在数据库中建立了三个表——用户信息表、失物招领表和寻物启事表。

用户信息表包含用户的用户名、密码以及一个用来标志用户类型的数据。

失物招领表包括对捡到物品的描述,对捡到物品地点的描述,对捡到物品时间的描述以及自己的联系方式。

寻物启示表包括对丢失物品的描述,对丢失地点的描述,对丢失时间段的描述以及自己的联系方式。

关于数据库的连接代码如下所示:

package util;

import java.sql.*;

public class DBUtil {

    private static Connection con;

private static String classname="com.mysql.jdbc.Driver";

private static String url="jdbc:mysql://localhost:3306/lost?useSSL=false&characterEncoding=UTF8";

public  static  Connection getConnection() {

     try{

     Class.forName(classname);

     }

     catch(ClassNotFoundException e){

     e.printStackTrace();

     }

     try{

         con=DriverManager.getConnection(url,"root","ms911");

     }

     catch(Exception e){

         e.printStackTrace(System.err);

     con=null;

     }

     return con;

}

public static void close(Connection connection ) {

try {

if (connection != null) {

connection.close();

}

 

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static void close(PreparedStatement preparedStatement ) {

try {

if (preparedStatement != null) {

preparedStatement.close();

}

 

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static void close(Statement statement ) {

try {

if (statement != null) {

statement.close();

}

 

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static void close(ResultSet resultSet ) {

try {

if (resultSet != null) {

resultSet.close();

}

 

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

 

}

同时我们对用户登录和注册界面进行了编写,关于对不同的用户类型登录到不同的功能界面,我们也写出相应的算法进行了判断。

登录和注册界面的代码如下所示:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>登陆界面</title>

<link rel="stylesheet" href="css/style.css" />

</head>

<body>

<body style="overflow-y: hidden">

<div class="login-box">

<h1>Login</h1>  

<form action="Login" method="post">

<div class="textbox">

<i class="iconfont2" ></i>

<input  type="text" name="userName" placeholder="Username" required="required">

</div>

<div class="textbox">

<i class="iconfont" ></i>

<input  type="password" name="password" placeholder="Password" required="required">

</div>

<input class="dbtn" type="submit" value="登录"/>

<br>

<input class="zbtn" type ="button" value="注册" onclick="window.location.href='zhuce.html'">

</form>

</div>

</body>

</html>

注册界面的代码如下所示:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>注册界面</title>

<link rel="stylesheet" href="css/style.css" />

</head>

<script>

function check(){

    if(insertform.zh.value==null||insertform.zh.value==""){

      alert("请输入注册的用户名!");

      insertform.zh.focus();

      return false;

    }

    if(insertform.password.value==null||insertform.password.value==""){

        alert("请输入注册的密码!");

        insertform.password.focus();

        return false;

    }

}

</script>

<body>

<body>

<div class="login-box">

<h1>Register</h1>

  <form action="dozhuce.jsp" name="insertform">

  <div class="textbox">

  <i class="iconfont2" ></i>

     <input type="text" placeholder="Username" name="zh" size="27">

   </div>

   <div class="textbox">

   <i class="iconfont" ></i>

     <input type="text" placeholder="Password" name="password" size="27">

    </div>

       <input class="cbtn" type="reset" name="reset" value="重置">     

       <input class="zbtn" type="submit" name="submit" value="注册" onclick="return check()">

  </form>

</div>

</body>

</html>

其对应的css文件代码如下所示:

body{

margin:0;

padding:0;

font-family:sans-serif;

background:url(../img/bg1.4.jpg) no-repeat;

background-size: cover;

}

.login-box{

width: 280px;

position: absolute;

top: 50%;

left: 50%;

transform: translate(-50%,-50%);

color: white;

}

.login-box h1{

float: left;

font-size: 40px;

border-bottom: 6px solid #4caf50;

margin-bottom: 50px;

padding: 13px 0;

}

.textbox{

width: 100%;

overflow: hidden;

font-size: 20px;

padding: 8px 0;

margin:8px 0;

border-bottom: 1px solid #4caf50;

}

/*.textbox i{

width: 26px;

float:left;

text-align: center;

}*/

.textbox input{

border: none;

outline: none;

background: none;

color: white;

font-size: 18px;

width:80%;

float: left;

margin: 0 10px;

}

.dbtn{

width: 100%;

background: none;

border:2px solid #4caf50;

color: white;

padding: 5px;

font-size: 18px;

cursor: pointer;

margin: 12px 0;

}

.zbtn{

width: 100%;

background: none;

border:2px solid #4caf50;

color: white;

padding: 5px;

font-size: 18px;

cursor: pointer;

margin: 12px 0;

}

.cbtn{

width: 100%;

background: none;

border:2px solid #4caf50;

color: white;

padding: 5px;

font-size: 18px;

cursor: pointer;

margin: 12px 0;

}

@font-face {

  font-family: 'iconfont';  /* project id 1194820 */

  src: url('//at.alicdn.com/t/font_1194820_iq6c8352b4h.eot');

  src: url('//at.alicdn.com/t/font_1194820_iq6c8352b4h.eot?#iefix') format('embedded-opentype'),

  url('//at.alicdn.com/t/font_1194820_iq6c8352b4h.woff2') format('woff2'),

  url('//at.alicdn.com/t/font_1194820_iq6c8352b4h.woff') format('woff'),

  url('//at.alicdn.com/t/font_1194820_iq6c8352b4h.ttf') format('truetype'),

  url('//at.alicdn.com/t/font_1194820_iq6c8352b4h.svg#iconfont') format('svg');

}

@font-face {

  font-family: 'iconfont';  /* project id 1194820 */

  src: url('//at.alicdn.com/t/font_1194820_44icvkodybk.eot');

  src: url('//at.alicdn.com/t/font_1194820_44icvkodybk.eot?#iefix') format('embedded-opentype'),

  url('//at.alicdn.com/t/font_1194820_44icvkodybk.woff2') format('woff2'),

  url('//at.alicdn.com/t/font_1194820_44icvkodybk.woff') format('woff'),

  url('//at.alicdn.com/t/font_1194820_44icvkodybk.ttf') format('truetype'),

  url('//at.alicdn.com/t/font_1194820_44icvkodybk.svg#iconfont') format('svg');

}

.iconfont{

font-family: "iconfont"!important;

font-size: 16px;

font-style: normal;

-webkit-font-smoothing: antialiased;

float: left;

}

.iconfont2{

font-family: "iconfont"!important;

font-size: 16px;

font-style: normal;

-webkit-font-smoothing: antialiased;

float: left;

}

判断登录账户信息正确性以及账户类型的代码如下所示:

package servlet;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import bean.User;

import dao.LoginerDaoImpl;

@WebServlet("/Login")

public class Login extends HttpServlet {

private static final long serialVersionUID = 1L;

    public Login() {

        super();

        // TODO Auto-generated constructor stub

    }

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

request.setCharacterEncoding("UTF-8");

@SuppressWarnings("unused")

HttpSession session=request.getSession();

User user=new User();

LoginerDaoImpl loginerDaoImpl=new LoginerDaoImpl();

String userName=request.getParameter("userName");

String password=request.getParameter("password");

if(userName==null||password==null||userName.equals("")||password.equals("")) {

response.sendRedirect("Denglu.html");

return;

}

user=loginerDaoImpl.loadUser(userName.trim());

if(user.getPassword().trim().equals(password)) {

if(user.getType()==1)

response.sendRedirect("Maintest.jsp");

if(user.getType()==2)

response.sendRedirect("jiemian2.jsp");

if(user.getType()==3)

response.sendRedirect("jiemian3.jsp");

}

if(!user.getPassword().trim().equals(password)) {

response.sendRedirect("login.jsp");

return;

}

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

doGet(request, response);

}

 

}

package dao;

 

import java.sql.*;

import bean.User;

import util.DBUtil;

 

public class LoginerDaoImpl{

public boolean dsAdd(String name, String place, String time1, String time2, String people) {

// TODO Auto-generated method stub

Connection connection = DBUtil.getConnection();

  if(place==null||place.equals("")){

  place="未留此信息!";

}

String sql = "insert into ds(name, place,time1,time2,people) values('" + name + "','" + place + "','" + time1 + "','" + time2 + "','" + people + "')";

Statement state = null;

boolean f = false;

int a = 0 ;

 

try {

state = connection.createStatement();

a = state.executeUpdate(sql);

} catch (Exception e) {

e.printStackTrace();

} finally {

//关闭z 连接

DBUtil.close(connection);

DBUtil.close(state);

}

 

if (a > 0) {

f = true;

}

return f;

}

public User loadUser(String userName) {

Connection connection = DBUtil.getConnection();

String sql = "select * from users where userName=?";

PreparedStatement preparedStatement = null;

ResultSet resultSet = null;

User user = null;

try {

preparedStatement = connection.prepareStatement(sql);

preparedStatement.setString(1, userName);

resultSet = preparedStatement.executeQuery();

while(resultSet.next()) {

user = new User();

user.setUserName(userName);

user.setPassword(resultSet.getString("password"));

user.setType(resultSet.getInt("type"));

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally {

DBUtil.close(connection);

DBUtil.close(resultSet);

DBUtil.close(preparedStatement);

}

return user;

 

}

 

}

对注册信息进行处理的代码为:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<jsp:useBean id="db" class="com.jb.db.zcDB"/>

<html>

<head>

 <title>增加学生信息</title>

  <link rel="stylesheet" type="text/css" href="css/style.css">

</head>

<%

  request.setCharacterEncoding("UTF-8");

  String   mess="";

  String   zh=request.getParameter("zh");

  String   password=request.getParameter("password");

  int type1=1;

  boolean mark=true;

  if(mark){

      String sql="insert into users values('"+zh+"','"+password+"',"+type1+")";

      int i=db.insert(sql);

      db.closed();

      if(i>0)

      {

       out.print("<script>alert('Successful!!!');window.location.href='Maintest.jsp'</script>");

      }

      else

       mess="插入失败!";

  }

%>

<body>

  <table>

   <tr bgcolor="lightgrey">

    <td>友情提示!</td>

   </tr>

   <tr>

    <td align="center"><%=mess%></td>

   </tr>

  </table>

  <a href="zhuce.jsp">[返回]</a>

</body>

</html>

关于登录和注册界面的美化,我们从网上找了合适的模板并进行了改进同时换上了合适的背景照片。

今日总结:

完成内容:今天我们根据所需要的信息完成了数据库的创建以及相关表的创建;我们实现了用户的登录和注册;我们实现了根据账户的类型跳转到不同的功能界面。

明天的计划:实现失物招领信息的展示和寻物启示信息的展示。

转载于:https://www.cnblogs.com/ruan1705/p/10883588.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值