javaweb 测试
题目要求:
1登录账号:要求由6到12位字母、数字、下划线组成,只有字母可以开头;(1分)
2登录密码:要求显示“• ”或“*”表示输入位数,密码要求八位以上字母、数字组成。(1分)
3性别:要求用单选框或下拉框实现,选项只有“男”或“女”;(1分)
4学号:要求八位数字组成,前四位为“2018”开头,输入自己学号;(1分)
5姓名:输入自己的姓名;
5电子邮箱:要求判断正确格式xxxx@xxxx.xxxx;(1分)
6点击“添加”按钮,将学生个人信息存储到数据库中。(3分)
7可以演示连接上数据库。(2分)
代码:
1连接数据库
import java.sql.SQLException;
import java.sql.Statement;
/**
* 数据库连接工具
* @author Hu
*
*/
public class DBUtil {
public static String db_url = "jdbc:mysql://localhost:3306/zzm?useSSL=false";
public static String db_user = "root";
public static String db_pass = "123456";
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();
}
}
}
private int id;
private String zhanghao;
private String password;
private String sex;
private String number;
private String name;
private String mail;
private String xueyuan;
private String zhuanye;
private String banji;
private String year;
private String shengyuandi;
private String beizhu;
public int getId()
{
return id;
}
public void setId()
{
this.id=id;
}
public String getZhanghao()
{
return zhanghao;
}
public void setZhanghao()
{
this.zhanghao=zhanghao;
}
public String getPassword()
{
return password;
}
public void setPassword()
{
this.password=password;
}
public String getSex()
{
return sex;
}
public void setSex()
{
this.sex=sex;
}
public String getName()
{
return name;
}
public void setName()
{
this.name=name;
}
public String getMail()
{
return mail;
}
public void setMail()
{
this.mail=mail;
}
public String getNumber()
{
return number;
}
public void setNumber()
{
this.number=number;
}
public String getXueyuan()
{
return xueyuan;
}
public void setXueyuan()
{
this.xueyuan=xueyuan;
}
public String getZhuanye()
{
return zhuanye;
}
public void setZhuanye()
{
this.zhuanye=zhuanye;
}
public String getBanji()
{
return banji;
}
public void setBanji()
{
this.banji=banji;
}
public String getYear()
{
return year;
}
public void setYear()
{
this.year=year;
}
public String getShengyuandi()
{
return shengyuandi;
}
public void setShengyuandi()
{
this.shengyuandi=shengyuandi;
}
public String getBeizhu()
{
return beizhu;
}
public void setBeizhu()
{
this.beizhu=beizhu;
}
public Lzx() {}
public Lzx(int id,String zhanghao,String password,String sex,String name,String number,String mail,String xueyuan,String zhuanye,String banji,String year,String shengyuandi,String beizhu)
{
this.id=id;
this.zhanghao = zhanghao;
this.password = password;
this.name = name;
this.sex = sex;
this.number =number;
this.name = name;
this.mail = mail;
this.xueyuan = xueyuan;
this.zhuanye = zhuanye;
this.banji = banji;
this.year = year;
this.shengyuandi = shengyuandi;
this.beizhu = beizhu;
}
public Lzx(String zhanghao, String password,String sex, String name,String number,String mail,String xueyuan,String zhuanye,String banji,String year,String shengyuandi,String beizhu)
{
this.zhanghao = zhanghao;
this.password = password;
this.name = name;
this.sex = sex;
this.number = number;
this.mail = mail;
this.xueyuan = xueyuan;
this.zhuanye = zhuanye;
this.banji = banji;
this.year = year;
this.shengyuandi = shengyuandi;
this.beizhu = beizhu;
}
}
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
*
* Dao层操作数据
* @author Zhao
*
*/
public class lzxDao {
* 添加
* @param zzm
* @return
*/
public boolean add(Lzx zzm) {
String sql = "insert into zzm(zhanghao,password,sex,name,number,mail,xueyuan,zhuanye,banji,year,shengyuandi,beizhu) values('" + zzm.getZhanghao() + "','" + zzm.getPassword() + "','" + zzm.getSex() + "','"+zzm.getName()+"','" + zzm.getNumber() + "','" + zzm.getMail()+"','"+zzm.getXueyuan()+"','"+zzm.getZhuanye()+"','"+zzm.getBanji() +"','"+zzm.getYear()+"','"+zzm.getShengyuandi()+"','"+zzm.getBeizhu() +"')";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0;
try {
state = conn.createStatement();
state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
// TODO Auto-generated method stub
return false;
}
/**
* ZzmService
* 服务层
* @author Zhao
*
*/
public class LzxService {
/**
* 添加
* @param Zzm
* @return
*/
public boolean add(Lzx zzm) {
boolean f = false;
if(!cDao.zhanghao(zzm.getZhanghao())) {
cDao.add(zzm);
f = true;
}
return f;
}
}
import java.util.List;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LzxServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
req.setCharacterEncoding("utf-8");
String method = req.getParameter("method");
if ("add".equals(method)) {
add(req, resp);
}
}
* 添加
* @param req
* @param resp
* @throws IOException
* @throws ServletException
*/
private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
req.setCharacterEncoding("utf-8");
String zhanghao = req.getParameter("zhanghao");
String password = req.getParameter("password");
String sex = req.getParameter("sex");
String number = req.getParameter("number");
String name = req.getParameter("name");
String mail = req.getParameter("mail");
String xueyuan = req.getParameter("xueyuan");
String zhuanye = req.getParameter("zhuanye");
String banji = req.getParameter("banji");
String year = req.getParameter("year");
String shengyuandi = req.getParameter("shengyuandi");
String beizhu = req.getParameter("beizhu");
Lzx zzm= new Lzx(zhanghao,password,sex,name,number,mail,xueyuan,zhuanye,banji,year,shengyuandi,beizhu);
//添加后消息显示
if(service.add(zzm)) {
req.setAttribute("message", "添加成功");
req.getRequestDispatcher("zzm.jsp").forward(req,resp);
} else {
req.setAttribute("message", "用户名重复,请重新输入");
req.getRequestDispatcher("zzm.jsp").forward(req,resp);
}
}
}
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="font/iconfont.css">
<script type="text/javascript" src="js/nav.js"></script>
<body>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
<form action="LzxServlet?method=add" method="post" onsubmit="return check()">
<td width="100"><font color="black"style="font-family:宋体;">登录账号:</font></td>
<td width="400"><input id="zhanghao" name="zhanghao" placeholder="请输入账号"/></td>
</tr>
<tr height="50px" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">登录密码:</font></td>
<td width="400"><input type="password" name="password" placeholder="请输入密码"/></td>
</tr>
<tr height="50" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">性别:</font></td>
<td><select id="sex" name="sex" >
<option value="男">男</option>
<option value="女">女</option>
<select></td>
</tr>
<tr height="50px" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">姓名:</font></td>
<td width="400"><input id="name" name="name" placeholder="请输入姓名"/></td>
</tr>
<tr height="50" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">学号:</font></td>
<td width="400"><input id="number" name="number" placeholder="请输入学号"/></td>
</tr>
<tr height="50" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">电子邮箱:</font></td>
<td width="400"><input id="mail" name="mail" placeholder="请输入邮箱" /></td>
</tr>
<tr height="50" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">所在学院:</font></td>
<td width="400"><input id="xueyuan" name="xueyuan" placeholder="请输入学院名" /></td>
</tr>
<tr height="50" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">所在专业:</font></td>
<td width="400"><input id="zhuanye" name="zhuanye" placeholder="请输入专业" /></td>
</tr>
<tr height="50" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">所在班级:</font></td>
<td width="400"><input id="banji" name="banji" placeholder="请输入班级" /></td>
</tr>
<tr height="50" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">入学年份:</font></td>
<td><select id="year" name="year" >
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<select></td>
</tr>
<tr height="50" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">生源地:</font></td>
<td width="400"><input id="shengyuandi" name="shengyuandi" placeholder="请输入生源地" /></td>
</tr>
<tr height="100" align="center" bgcolor="#FFFFCC">
<td width="100"><font color="black"style="font-family:宋体;">备注:</font></td>
<td width="400"><input id="beizhu" name="beizhu" placeholder="无" /></td>
</tr>
<td width="400"><button type="submit" >添加<button></td>
<td width="400"><input type="reset" value="重新输入" /></td>
</tr>
</form>
</div>
<script type="text/javascript">
function check() {
var zhanghao = document.getElementById("zhanghao");
var password = document.getElementById("password");
var number = document.getElementById("number");
var mail = document.getElementById("mail");
if (!zhanghao.value.match(/^[a-zA-Z]\w{5,11}$/)) {
else if(number.value<"20180000"|| number.value>"20189999")
{
alert(" 学号由2018开头的八位组成");
number.focus();
}
</script>
</body>
</html>
javaweb 测试的更多相关文章
- Javaweb测试
1.建立web 工程 输入Project name.然后点击finish. 2.右键点击WebContent-New-JSP File,新建jsp文件. 3.然后编写一个jsp登录的程序 <%@ ...
- IDEA新建javaWeb以及Servlet简单实现
刚开始用IDEA开发,还不太熟悉,因此写一个教程,加深印象 1.新建一个Web项目 两种方法:java 和 Java Enterprise(推荐) 第一种)通过Java工程创建,这个方法需要手动导入T ...
- Intellij IDEA创建javaWeb以及Servlet简单实现
1.创建web工程 File --> New --> Project...
- Intellij IDEA创建javaweb步骤详解
一.创建并设置javaweb工程 1.创建javaweb工程File --> New --> Project... 设置工程名字: 创建完成后工程结构如下: 2. Web工程设置2.1 在 ...
- [转]Intellij idea创建javaWeb以及Servlet简单实现
准备:1. 安装jdk1.72. 安装tomcat1.8 一.创建并设置javaweb工程 1.创建javaweb工程File --> New --> Project... 设置工程名字: ...
- Inellij idea创建javaWeb以及Servlet简单实现
版权声明:本文为博主原创文章,未经博主允许不得转载. 准备:1. 安装jdk1.7 2. 安装tomcat1.8 一.创建并设置javaweb工程 1.创建javaweb工程File --> N ...
- Intellij idea创建javaWeb:实现JSP/Servlet(转)
转自:https://www.jianshu.com/p/9684e90cf7b5 Intellij idea创建javaWeb:实现JSP/Servlet by_love唯念 关注 2016.12. ...
- IDEA下配置JavaWeb项目
前提 已安装IDEA专业版 已安装Tomcat 已安装JDK 创建JavaWeb项目 File --> New --> Project... 设置工程名字: 创建完成后工程结构如下: 设置 ...
- WebSocket简单介绍
Java后端WebSocket的Tomcat实现 一.WebSocket简单介绍 随着互联网的发展,传统的HTTP协议已经很难满足Web应用日益复杂的需求了.近年来,随着HTML5的诞生,WebSoc ...
随机推荐
- Django setting设置 常用设置
目录 Django配置文件基本设置 前言 setting配置汇总 一.APP路径 二.数据库配置 三.sql语句展示 四.静态文件目录 五.media文件配置 六.数据库中的UserInfo(用户表) ...
- 数据可视化基础专题(四):Pandas基础(三) mysql导入与导出
转载(有添加.修改)作者:但盼风雨来_jc链接:https://www.jianshu.com/p/238a13995b2b來源:简书著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处 ...
- VMWare WorkStation中MacOS虛擬機無法啓動的問題
關於MacOS虛擬機,在有VMWare重裝,升級以及MacOS更新時,都可能會造成破解補丁失效,因此儅Mac虛擬機無法啓動時,可以嘗試以下操作: 重新運行unlocker208中的win-instal ...
- 太实用了!自己动手写软件——GUI编程
这几天我有一个想法就是将我之前做测试写的一些协议脚本(如:ssh.FTP.SMTP.MySQL.Oracle等)综合在一起做一个密码PJ器,这么多的协议放在一起,每个协议都有自己特殊的参数,如果还是和 ...
- Ethical Hacking - NETWORK PENETRATION TESTING(13)
Nmap Nmap is a network discovery tool that can be used to gather detailed information about any clie ...
- JAVA集合二:HashMap和Hashtable
参考链接: HOW2J.CN HashMap HashMap实现了JAVA的Map接口,类似于C++的STL框架的Map,是存储键值对的数据结构.键(key)是唯一的,但值(value)可以重复,如果 ...
- 搭建jmeter+influxdb+grafana压测实时监控平台(超详细,小白适用)
1.前言 在使用jmeter做性能测试的时候,监控系统性能的时候,无论是使用插件还是报告生成,都没法实现实时监控.使用JMeter+Influxdb+Grafana可以实现实时监控. 本次环境搭建各软 ...
- Pull后产生多余的log(Merge branch 'master' of ...)
第一步: git reset --hard 73d0d18425ae55195068d39b3304303ac43b521a 第二步: git push -f origin feature/PAC_1 ...
- django-rest-framework-源码解析004-三大验证(认证/权限/限流)
三大验证模块概述 在DRF的APIView重写的dispatch方法中, self.initial(request, *args, **kwargs) 这句话就是执行三大验证的逻辑, 点进去可以看到 ...
- jmeter接口测试 -- 上传文件(multipart/form-data数据请求)
一.环境 jmeter5.2.1 二.具体步骤 1.抓取接口的请求数据 2.填写jmeter的数据 1) 信息头管理器 2) 填写 “参数” 3) 填写 “文件上传” 三.检验接口. 1.响应数据 - ...