软件工程系统开发课堂测试01

这次测试我们尝试的编辑了河北省重大技术需求证据系统,程序需求用户注册,用户登陆,系统主机面,需求征集,浏览需求,需求审核,修改密码等功能,并且需要进行数据库的连接,这些内容大部分在上一学期就有了些许的掌握,但在课堂测试的过程中,我还是只完成了部分功能,我只满足了用户注册,用户登陆,需求征集,修改密码这几个功能,并与数据库正常连接,图形化界面也并没有完成,下面我将展示我的代码。

//Dao.java
package Dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import Entity.User;
import Entity.jishu;
import DB.DB;

public class Dao {
    public String denglu(String username) {
        String sql = "select * from yonghu where ";
        if (username != "") {
            sql += "name like ‘%" + username + "%‘";
        }

        Connection conn = DB.getConn();
        Statement state = null;
        ResultSet rs = null;
        String password2 = null;
        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {

                password2 = rs.getString("password");

            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs, state, conn);
        }

        return password2;
    }
    public boolean zhuce(User user) {
        String sql = "insert into yonghu(name, password,tel,danwei) values(‘" + user.getName() + "‘,‘" + user.getPassword()+ "‘,‘" + user.getTel()+ "‘,‘" + user.getDanwei()
                + "‘)";
        // 鍒涘缓鏁版嵁搴撻摼鎺?
        Connection conn = DB.getConn();
        Statement state = null;
        boolean f = false;
        int a = 0;

        try {
            state = conn.createStatement();
            a = state.executeUpdate(sql);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 鍏抽棴z 杩炴帴
            DB.close(state, conn);
        }

        if (a > 0) {
            f = true;
        }
        return f;
    }
    public boolean zhengji(jishu js) {
        String sql = "insert into jishu(name, info,val,moshi,touzi) values(‘" + js.getName() + "‘,‘" + js.getInfo()+ "‘,‘" + js.getValues()+ "‘,‘" + js.getMoshi()+ "‘,‘" + js.getTouzi()
                + "‘)";
        // 鍒涘缓鏁版嵁搴撻摼鎺?
        Connection conn = DB.getConn();
        Statement state = null;
        boolean f = false;
        int a = 0;

        try {
            state = conn.createStatement();
            a = state.executeUpdate(sql);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 鍏抽棴z 杩炴帴
            DB.close(state, conn);
        }

        if (a > 0) {
            f = true;
        }
        return f;
    }

}
//DB.java
package DB;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DB {
    public static String db_url = "jdbc:mysql://localhost:3306/course";
    public static String db_user = "root";
    public static String db_pass = "z376371066.";

    public static Connection getConn () {
        Connection conn = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");//鍔犺浇椹卞姩
            conn = DriverManager.getConnection(db_url, db_user, db_pass);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return conn;
    }

    /**
     * 鍏抽棴杩炴帴
     * @param state
     * @param conn
     */
    public static void close (Statement state, Connection conn) {
        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close (ResultSet rs, Statement state, Connection conn) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws SQLException {
        Connection conn = getConn();
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        String sql ="select * from USER";
        pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();
        if(rs.next()){
            System.out.println("绌?");
        }else{
            System.out.println("涓嶇┖");
        }
    }

}
//jishu.java
package Entity;

public class jishu {
    private String name;
    private String info;
    private String values;
    private String moshi;
    private String touzi;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getInfo() {
        return info;
    }
    public void setInfo(String info) {
        this.info = info;
    }
    public String  getValues() {
        return values;
    }
    public void setValues(String values) {
        this.values = values;
    }
    public String getMoshi() {
        return moshi;
    }
    public void setMoshi(String moshi) {
        this.moshi = moshi;
    }
    public String getTouzi() {
        return touzi;
    }
    public void setTouzi(String touzi) {
        this.touzi = touzi;
    }
    public jishu(String name,String info,String values,String moshi,String touzi) {
        this.name = name;
        this.info = info;
        this.values = values;
        this.moshi = moshi;
        this.touzi = touzi;
    }
}
//User.java
package Entity;

public class User {
    private String name;
    private String password;
    private String tel;
    private String danwei;
    public String getTel() {
        return tel;
    }
    public void setTel(String tel) {
        this.tel = tel;
    }
    public String getDanwei() {
        return danwei;
    }
    public void setDanwei(String danwei) {
        this.danwei = danwei;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public User(String name,String password) {
        this.name = name;
        this.password = password;
    }
    public User(String name,String password,String tel,String danwei) {
        this.name = name;
        this.password = password;
        this.tel = tel;
        this.danwei = danwei;
    }

}
//Servlt.java
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 Dao.Dao;
import Entity.User;
import Entity.jishu;

/**
 * Servlet implementation class Servlet
 */
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    Dao dao = new Dao();
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String method = req.getParameter("method");
        if ("denglu".equals(method)) {
            denglu(req, resp);
        }  else if ("zhuce".equals(method)) {
            zhuce(req, resp);
        }
         else if ("zhengji".equals(method)) {
                zhengji(req, resp);
            }
    }
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    private void denglu(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        // TODO Auto-generated method stub
        req.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String rpassword = dao.denglu(username);
        if(password.equals(rpassword)) {
            req.setAttribute("message", "鐧婚檰鎴愬姛锛?");
            req.getRequestDispatcher("index.jsp").forward(req,resp);
        }
        else {
            req.setAttribute("message", "璐﹀彿涓嶅瓨鍦ㄦ垨瀵嗙爜閿欒锛?");
            req.getRequestDispatcher("login.jsp").forward(req,resp);
        }

    }
    private void zhuce(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        // TODO Auto-generated method stub
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String tel = req.getParameter("tel");
        String danwei = req.getParameter("danwei");

        User user= new User(username,password,tel,danwei);
        if(dao.zhuce(user)) {
            req.setAttribute("message", "娉ㄥ唽鎴愬姛!");
            req.getRequestDispatcher("login.jsp").forward(req, resp);
        }else {
            req.setAttribute("message", "璐﹀彿閲嶅锛岃閲嶆柊杈撳叆!");
            req.getRequestDispatcher("zhuce.jsp").forward(req, resp);
        }
    }
    private void zhengji(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        // TODO Auto-generated method stub
        String name = req.getParameter("name");
        String info = req.getParameter("info");
        String[] values = req.getParameterValues("type");
        String moshi = req.getParameter("moshi");
        String touzi = req.getParameter("touzi");

        String delStr = "";
        for(int i=0 ;i < values.length ; i ++)
            delStr += values[i] +" ";

        jishu js = new jishu(name,info,delStr,moshi,touzi);
        if(dao.zhengji(js)) {
            req.setAttribute("message", "闇?姹傚緛闆嗗~鍐欐垚鍔?!");
            req.getRequestDispatcher("index.jsp").forward(req, resp);
        }else {
            req.setAttribute("message", "闇?姹傚緛闆嗗~鍐欏け璐ワ紒");
            req.getRequestDispatcher("register.jsp").forward(req, resp);
        }
    }

}
//index.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>Insert title here</title>
</head>
<body>
<%
         Object message = request.getAttribute("message");//放置一个字符串,并取出
         if(message!=null && !"".equals(message)){

    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
<h2 align="center">主界面</h2>

<p style="text-align:center" ><a href="login.jsp"> <font size="4">返回登陆界面</font></a></p>
<div align="center">

        <div class="a">
            <p style="text-align:center"><a href="register.jsp">1.需求征集</a></p>
        </div>
        <div class="a">
            <p style="text-align:center"><a href="Servlet?method=list">2.浏览需求</a></p>
        </div>
        <div class="a">
            <p style="text-align:center"><a href="">3.需求审核</a></p>
        </div>
        <div class="a">
            <p style="text-align:center"><a href="zhuce.jsp">4.用户注册</a></p>
        </div>
        <div class="a">
            <p style="text-align:center"><a href="change.jsp">5.修改密码</a></p>
        </div>

    </div>

</body>
</html>
//login.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>Insert title here</title>
</head>
<body>
<%
         Object message = request.getAttribute("message");//放置一个字符串,并取出
         if(message!=null && !"".equals(message)){

    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: black;">河北省重大技术需求</h1>
        <h1 style="color: black;">征集系统</h1>
        <form action="Servlet?method=denglu" method="post" onsubmit="return check()">
            <div class="a">
                <p style="text-align:center">账号<input type="text" size="20" id="username" name="username"/></p>
            </div>
            <div class="a">
                <p style="text-align:center">密码<input type="password" size="20" id="password" name="password" /></p>
            </div>
            <div class="a">
                <p style="text-align:center">验证码<input type="text" size="20" id="yanzhengma" name="yanzhengma"/></p>
            </div>
            <div class="a">
                <button type="submit" class="b">登&nbsp;&nbsp;&nbsp;陆</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var username = document.getElementById("username");;
            var password = document.getElementById("password");
            //非空
            if(username.value == ‘‘) {
                alert(‘账号不能为空‘);
                username.focus();
                return false;
            }
            if(password.value == ‘‘) {
                alert(‘密码不能为空‘);
                password.focus();
                return false;
            }

        }
    </script>
    <p style="text-align:center"><a href="zhuce.jsp"><font SIZE="6"  >注册</font></a></p>
</body>
</html>
//zhuce.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>Insert title here</title>
</head>
<body>
<%
         Object message = request.getAttribute("message");//放置一个字符串,并取出
         if(message!=null && !"".equals(message)){

    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: black;">注册界面</h1>
        <a href="login.jsp">返回登陆界面</a>
        <form action="Servlet?method=zhuce" method="post" onsubmit="return check()">
            <div class="a">
                姓名<input type="text" id="username" name="username"/>
            </div>
            <div class="a">
                密码<input type="password" id="password" name="password" />
            </div>
            <div class="a">
                重复密码<input type="password" id="rpassword" name="rpassword" />
            </div>
            <div class="a">
                手机号码<input type="text" id="tel" name="tel"/>
            </div>
            <div class="a">
                所属单位<input type="text" id="danwei" name="danwei"/>
            </div>
            <div class="a">
                <button type="submit" class="b">注&nbsp;&nbsp;&nbsp;册</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var username = document.getElementById("username");;
            var password = document.getElementById("password");
            var rpassword = document.getElementById("rpassword");
            var tel = document.getElementById("tel");
            var danwei = document.getElementById("danwei");

            //非空
            if(username.value == ‘‘) {
                alert(‘账号不能为空‘);
                username.focus();
                return false;
            }
            if(password.value == ‘‘) {
                alert(‘密码不能为空‘);
                password.focus();
                return false;
            }
            if(rpassword.value == ‘‘) {
                alert(‘确认密码不能为空‘);
                rpassword.focus();
                return false;
            }
            if(rpassword.value!= password.value) {
                alert(‘两次密码不一致‘);
                rpassword.focus();
                return false;
            }
            if(tel.value == ‘‘) {
                alert(‘手机号不能为空‘);
                tel.focus();
                return false;
            }
            if(tel.length()!=11) {
                alert(‘手机号码必须为11位‘);
                tel.focus();
                return false;
            }
            if(danwei.value == ‘‘) {
                alert(‘所属单位不能为空‘);
                danwei.focus();
                return false;
            }

        }
    </script>
</body>
</html>
//register.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>Insert title here</title>
</head>
<body>
<body>
<%
         Object message = request.getAttribute("message");//放置一个字符串,并取出
         if(message!=null && !"".equals(message)){

    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: black;">河北省重大技术需求征集表</h1>
        <a href="index.jsp">返回主界面</a>
        <form action="Servlet?method=zhengji" method="post" >
            <div class="a">
                技术需求名称<input type="text" id="name" name="name"/>
            </div>
            <div class="a">
                <textarea name="info" cols="35" rows="7">重大科技需求概述</textarea>
            </div>
            <div class="a">
                研究类型<br /><br />
             <label><input name="type" type="checkbox" value="基础研究" />基础研究 </label>
             <label><input name="type" type="checkbox" value="应用研究" />应用研究 </label>
             <label><input name="type" type="checkbox" value="试验发展" />试验发展 </label>
             <label><input name="type" type="checkbox" value="研究发展与成果应用" />研究发展与成果应用 </label>
             <label><input name="type" type="checkbox" value="技术推广与科技服务" />技术推广与科技服务 </label> 

            </div>
            <div class="a">
                <p>技术需求合作模式<input name = "moshi" type = "radio" value="独立开发">独立开发<input name = "moshi" type = "radio" value="技术转让">技术转让<input name = "moshi" type = "radio" value="技术入股">技术入股<input name = "moshi" type = "radio" value="合作开发">合作开发</p>
            </div>
            <div class="a">
                <p>计划总投资<input type="text" size="20" id="touzi" name="touzi"/>万元</p>
            </div>
            <div class="a">
                <button type="submit" class="b">提&nbsp;&nbsp;&nbsp;交</button>
            </div>
        </form>
    </div>

</body>
</html>

原文地址:https://www.cnblogs.com/my---world/p/10465843.html

时间: 2024-11-08 01:21:56

软件工程系统开发课堂测试01的相关文章

Java课堂测试01及感想

上周进行了Java的开学第一次测验,按要求做一个模拟ATM机功能的程序,实现存取款.转账汇款.修改密码.查询余额的操作.这次测验和假期的试题最大的不同还是把数组存储改成的文件存储,在听到老师说要用文件的时候,还是有种悔不当初的感觉的,假期里找的教程是有教文件的,当时想着假期给的试题仅要求数组,就偷了懒.这次测验的时候,看了一下文件的教程,不是怎么清楚怎么像题目那样使用文件,便放弃了这一部分,还是用的数组.这次测验还发现了自己的很多问题,特别是一些习惯上的问题.以前写的都是几十行的小程序,简单看下

课堂测试01

一: 1,JAVA的基本运行单位是类 2,类的成员:成员变量,构造方法,普通方法和内部类 3,成员变量种类:字符类型:char        布尔类型:boolean     数值类型:byte, short ,int  long ,float ,double 浮点类型:float ,double 4,String 不是基本数据类型而是类 5,static含义:表示"全局"或者"静态"的意思 用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java

JAVA语言课堂测试01源代码(学生成绩管理系统)

package 考试; /*信1807-8 * 20183798 * 向瑜 */ import java.util.Scanner; //ScoreInformation 类 class ScoreInformation { private String stunumber; private String name; private double mathematicsscore; private double englishscore; private double networkscore;

现代软件工程团队项目贝塔阶段_开发日志_2018.01.15-2018.01.19

现代软件工程团队项目贝塔阶段_开发日志_2018.01.15-2018.01.19 2018.01.15 已完成: 1.版本上线 1.1上线操作步骤 1.1.1将网站整体文件夹拷贝到keqi1 1.1.2修改microDefinition.php的数据库名和根目录名 1.1.3修改注册界面发送验证码后直接填充功能 1.1.4修改del的主id的class为hide 1.1.5重新运行根目录的111.php(消除红点,也就是消除服务器返回的多余字符) 1.2修复上线过程中遇到的bug  1.2.1

[课程设计]Scrum 1. 9 多鱼点餐系统开发进度(最后页面完善&amp;修复BUG&amp;用户测试反馈)

[课程设计]Scrum 1. 9 多鱼点餐系统开发进度(最后页面完善&修复BUG&用户测试) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅到店点餐系统WEB 5.Sprint 1时间:11.14-11.23 重案组成员   姓名 学号 博客链接 Github链接 队长 黄冠锋 201406114134 http://www.cnblogs.com/hgf520/ https://github.com/crow

面向 Java 开发与测试人员的远程执行 Linux/UNIX 系统上任务的框架 -- sshxcu

软件开发与测试人员常常会在远程 Linux/UNIX 系统上执行命令或脚本,有时还会有批量执行任务的需求.常见的办法是通过本地工具(例如 Putty)连接远程计算机,输入命令执行,但是当遇到需要集成这些任务到代码或者开发.测试框架中时,往往就没有很好的解决方案了.sshxcute 就是这样一个框架工具集,它基于 JSCH 构建,允许工程师利用 Java 代码通过 SSH 连接远程批量执行 Linux/UNIX 系统上的命令或者脚本,同时加入了判断成功与否,取回输出等多种实用功能.sshxcute

迅为6818开发板Ubuntu系统下CAN 测试使用文档

平台:iTOP-6818开发板系统:Ubuntu12.04主要是在 Ubuntu 系统环境下 iTOP-4418 和 6818 的 CAN 实验调试步骤.给用户提供了"can_libs.rar"."can_libs_more.zip"."can_tools.zip"和"can_test.zip"压缩包,分别是 can 工具需要的库文件.can 工具二进制文件以及 can 实验Qt 源码.CAN 是 Controller Are

课堂测试1 登录界面

1.网站系统开发需要什么技术 前台photoshop(美工必学的)+dreaweaver(css+div)+javacript,后台php .net  asp 等编程语言,要想做好网站HTML.JAVASCRIPT.CSS.数据库.服务器配置必须要学会. 在网上查了一下,要做好一个网站系统,要学习的技术有很多,简单列举一下: (1)java Java语言体系比较庞大,包括多个模块.从WEB项目应用角度讲有JSP.Servlet.JDBC.JavaBean(Application)四部分技术. (

Linux系统开发6 信号

[本文谢绝转载,原文来自http://990487026.blog.51cto.com] <大纲> Linux系统开发6 信号 linux系统有64种信号 signal man文档 终端按键信号 ctrl +c SIGIN ctrl +z SIGTSTP ctrl +\ SIGQUIT 硬件产生信号 浮点数例外信号  访问非法内存 kill()函数 信号与权限 kill()函数的pid 与返回值 信号产生原因 raise() 信号 abort() 信号 alarm() 信号 收到信号的默认操作