Java Web学生信息保存
Course.java
package entity;
public class Course {
private int id;
private String num;
private String mima;
private String sex;
private String name;
private String studentnum;
private String youxiang;
private String xueyuan;
private String xi;
private String banji;
private String year;
private String plase;
private String beizhu;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getMima() {
return mima;
}
public void setMima(String mima) {
this.mima = mima;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getStudentnum() {
return studentnum;
}
public void setStudentnum(String studentnum) {
this.studentnum = studentnum;
}
public String getYouxiang() {
return youxiang;
}
public void setYouxiang(String youxiang) {
this.youxiang = youxiang;
}
public String getXueyuan() {
return xueyuan;
}
public void setXueyuan(String xueyuan) {
this.xueyuan = xueyuan;
}
public String getXi() {
return xi;
}
public void setXi(String xi) {
this.xi = xi;
}
public String getBanji() {
return banji;
}
public void setBanji(String banji) {
this.banji = banji;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getPlase() {
return plase;
}
public void setPlase(String plase) {
this.plase = plase;
}
public String getBeizhu() {
return beizhu;
}
public void setBeizhu(String beizhu) {
this.beizhu = beizhu;
}
public String getName() {
return name;
}
public Course() {} public Course( String num, String mima, String sex, String name, String studentnum, String youxiang, String xueyuan, String xi, String banji, String year, String plase, String beizhu) { this.num = num;
this.mima = mima;
this.sex = sex;
this.name = name;
this.studentnum = studentnum;
this.youxiang = youxiang;
this.xueyuan = xueyuan;
this.xi = xi;
this.banji = banji;
this.year = year;
this.plase = plase;
this.beizhu = beizhu;
}
}
CourseServlet.java
package servlet;
import java.io.IOException;
import java.util.List;
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 entity.Course;
import dao.CourseDao;public class CourseServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public CourseServlet() {
super();
}
CourseDao dao = new CourseDao();
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String method = req.getParameter("method");
if ("add".equals(method)) {
add(req, resp);
}
}
private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
req.setCharacterEncoding("utf-8");
String num = req.getParameter("num");
String mima = req.getParameter("mima");
String name = req.getParameter("name");
String sex = req.getParameter("sex");
String studentnum = req.getParameter("studentnum");
String xueyuan = req.getParameter("xueyuan");
String xi = req.getParameter("xi");
String banji = req.getParameter("banji");
String year = req.getParameter("year");
String plase = req.getParameter("plase");
String beizhu = req.getParameter("beizhu");
String youxiang = req.getParameter("youxiang");
Course course = new Course(num,mima,sex,name,studentnum,youxiang,xueyuan,xi,banji,year,plase,beizhu);
//添加后消息显示
if(dao.add(course)){
req.setAttribute("message", "注册成功");
req.getRequestDispatcher("index.jsp").forward(req,resp);}
else {
req.setAttribute("message", "注册失败");
req.getRequestDispatcher("zhuce.jsp").forward(req,resp);}
}
}
CourseDao.java
package dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import entity.Course;
import util.DBUtil;
public class CourseDao {
public boolean add(Course course) {
String sql = "insert into information( num , mima , sex, name , studentnum, youxiang,xueyuan,xi,banji,year,plase,beizhu) values('" + course.getNum() + "','" + course.getMima() + "','" + course.getSex() + "','" + course.getName()+"','" + course.getStudentnum()+"','" + course.getYouxiang()+"','" + course.getXueyuan()+"','" + course.getXi()+"','" + course.getBanji()+"','" + course.getYear()+"','" + course.getPlase()+"','" + course.getBeizhu()+"')";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0;
try {
state = conn.createStatement();
a=state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
}
DBUtil.java
package util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
public static String db_url = "jdbc:mysql://localhost:3306/text1?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;
}
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();
}
}
}
}
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
成功
</body>
</html>
zhucu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: white;
background-color: greenyellow;
}
</style>
</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: red;">注册</h1>
<form action="CourseServlet?method=add" method="post" onsubmit="return check()">
<div class="a">
登录账号<input type="text" id="num"name="num" value=""/> </div>
<div class="a">
登录密码:<input type="password" id="mima"name="mima" value="" />
</div>
性别: <select name="sex" >
<option value="男">男</option>
<option value="女">女</option> </select>
<div class="a">
姓名:<input type="text" name="name" value="" />
</div>
<div class="a">
学号:<input type="text" id="studentnum"name="studentnum" value="" />
</div>
<div class="a">
电子邮件:<input type="text" id="youxiang" name="youxiang" value="" />
</div>
<div class="a">
所在学院:<input type="text" name="xueyuan" value="" />
</div>
<div class="a">
所在系:<input type="text" name="xi" value="" />
</div>
<div class="a">
所在班级:<input type="text" name="banji" value="" />
</div>
入学年份(届)<select name="year">
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
</select>届
<div class="a">
生源地:<input type="text" name="plase" value=""/>
</div>
<div class="a">
备注:<textarea rows="10" cols="50" name="beizhu">
</textarea>
</div>
<div class="a">
<button type="submit" class="b">保 存</button>
</div>
</form>
</div>
<script type="text/javascript">
function check() {
var num = document.getElementById("num");
var mima = document.getElementById("mima");
var studentnum = document.getElementById("studentnum");
var youxiang = document.getElementById("youxiang");
if (!num.value.match(/^[a-zA-Z]\w{5,11}$/)) {
alert("用户名由六到十二英文字符和数字组成,以英文字母开头");
num.focus();
return false;
}
else if (!mima.value.match(/^[A-Za-z0-9]\w{7,20}$/)) {
alert(" 密码由八 位 以上英文 和数 字 组成");
mima.focus();
return false;
}
else if(studentnum.value<"20180000"|| studentnum.value>"20189999")
{
alert(" 学号由2018开头的八位组成");
studentnum.focus();
return false;
}
else if (!youxiang.value.match(/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/)) {
alert(" 邮箱格式错误");
youxiang.focus();
return false;
}
}
</script>
</body>
</html>
Java Web学生信息保存的更多相关文章
- java web 学生信息录入
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- Java 实现学生信息管理系统
编写一个简单的学生管理信息系统. 在oracle中设计一张学生表,以学号作为关键字. 其他学生信息有:姓名.手机号. 在进入系统时,显示如下菜单: ************************** ...
- java开发学生信息管理系统的实现(简洁易懂),适合计算机专业学生参考,课程设计、毕业论文设计参考等
编写一个简单的学生管理信息系统. 在oracle中设计一张学生表,以学号作为关键字. 其他学生信息有:姓名.手机号. 在进入系统时,显示如下菜单: ************************** ...
- java web 增加信息课堂测试00
按照图片要求设计添加新课程界面.(0.5分)在后台数据库中建立相应的表结构存储课程信息.(0.5分)实现新课程添加的功能.要求判断任课教师为王建民.刘立嘉.刘丹.王辉.杨子光五位教师的其中一位.(0. ...
- JAVA之学生信息管理系统
StudentManager系统 系统的数据: 变量 stunumber 为字符串类型 String,用于存储学生的学号(有 8 位数字组成) 变量 name 为字符串类型 String,用于存储学生 ...
- Java web项目 上传图片保存到数据库,并且查看图片,(从eclipse上移动到tomact服务器上,之路径更改,包括显示图片和导出excel)
//项目做完之后,在本机电脑运行完全正常,上传图片,显示图片,导出excel,读取excel等功能,没有任何问题,但是,当打成war包放到服务器上时,这些功能全部不能正常使用. 最大的原因就是,本机测 ...
- java开发学生信息管理系统 源码
开发环境: Windows操作系统开发工具: Eclipse+Jdk+Tomcat+MYSQL数据库 运行效果图 源码及原文链接:https://javadao.xyz/forum.php?mo ...
- 学生信息的添加 Java web简单项目初试(修改)
错误原因: 1.Java web 的Servlet类没有配置好,并且缺少一个 Dao类(Date Access Object通常用于操作数据库的). 2.代码的某些名称错误,导致数据库数据存储错误. ...
- 初学Java Web(9)——学生管理系统(简易版)总结
项目开始时间:2018年4月8日14:37:47 项目完成时间:2018年4月9日10:03:30 技术准备 这个项目是自己用于巩固 J2EE 相关知识的练手项目,非常简单,但是相关的功能却非常实用, ...
随机推荐
- LeetCode刷题笔记和想法(C++)
主要用于记录在LeetCode刷题的过程中学习到的一些思想和自己的想法,希望通过leetcode提升自己的编程素养 :p 高效leetcode刷题小诀窍(这只是目前对我自己而言的小方法,之后会根据自己 ...
- rally问题合集
rally 执行过程中涉及到keystone的用例,需要调用adminurl,在-/rally/lib/python2.7/site-packages/rally/osclients.py(主机文件的 ...
- window和document的区别理解,bom和dom的区别理解
Window对象: 是整个BOM的核心,所有对象和集合都以某种方式回接到window对象.Window对象表示整个浏览器窗口,但不必表示其中包含的内容. Document对象: 实际上是window对 ...
- english-phoneme
1. 声音概述 2. 音素phoneme与音标 2.1 音素与音标 2.2 音素与字母 2.3 字母发音-字母自然发音对照表 2.4 音标表 2.5 元音字母-辅音字母表 2.6 单元音发音口形趋势表 ...
- Ajax--数据格式
1.从服务端接收数据的时候,那些数据必须以浏览器能够理解的格式来发送,服务器端的编程语言智能以如下三种格式返回数据:1)XML; 2)JSON; 3)HTML; 2.解析HTML: --HTML由一些 ...
- 配置antMatchers(HttpMethod.GET,"/**").permitAll()当时仍然会校验
.antMatchers(HttpMethod.GET,"/**").permitAll() .anyRequest().authenticated() .and() .addFi ...
- eos 智能合约开发体验
eos编译安装 eos 特性 数据存储 eos投票智能合约开发 eos投票智能合约部署测试 注意避坑 eos编译安装 ERROR: Could not find a package configura ...
- 题目:给定一数组 例如:a = [1,2,3,5,2,1] 现用户提供一个数字 请返回用户所提供的数字的所有下标
def test(ary): ds = {} for i in range(len(ary)): if ds.get(ary[i]): ds[ary[i]].append(i) else: ds[ar ...
- 洛谷 P1929 迷之阶梯
题目传送门 解题思路: f[i]表示跳到第i层的最少移动次数,如果可以从下面一级跳上来,那么直接跳上来,如果跳不上来,那就往后退,退到不能退或能跳上第i层 AC代码: #include<iost ...
- jenkins#安装jenkins之后的操作
1.全局安全配置 运行用户注册 任何用户可以做任何事情 2.全局工具配置 指定maven的settings文件位置 指定java信息 指定maven信息 指定git信息