概述
本系统用到的工具是IDEA+MYSQL+tomcat9
通过servlet+jsp+javabean实现
数据库表结构如下,数据库名称为studentinfo
这是刚开始录入的一些数据
项目结构如下
部分jsp,servlet代码
student.jsp
<%--
Created by IntelliJ IDEA.
User: l1957
Date: 2021/2/16
Time: 13:18
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=GBK" language="java" pageEncoding="GBK" %>
<%@ page import="com.lqc.factory.*,com.lqc.vo.*"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>student list</title>
</head>
<% request.setCharacterEncoding("GBK");%>
<body>
<%
String keyWord=request.getParameter("cx");
if(keyWord==null){
keyWord="";
}
List<Student> all= null;
try {
all = DAOFactory.getIStudentDAOInstance().findAll(keyWord);
} catch (Exception e) {
e.printStackTrace();
}
Iterator<Student> iter=all.iterator();
%>
<center>
<table>
<tr>
<td>
<form action="${pageContext.request.contextPath}/JSP/student.jsp" method="post">
请输入查询关键字:<input type="text" name="cx">
<input type="submit" value="查询">
</form>
</td>
<td>
<form action="${pageContext.request.contextPath}/JSP/addstudent.jsp" method="post">
<input type="submit" value="增加">
</form>
</td>
</tr>
</table>
<table border="1" width="80%">
<tr>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>生日</td>
<td>电话</td>
<td>操作</td>
</tr>
<%
while(iter.hasNext()){
Student student=iter.next();
%>
<tr>
<td><%=student.getSno()%></td>
<td><%=student.getSname()%></td>
<td><%=student.getSex()%></td>
<td><%=student.getSbirth()%></td>
<td><%=student.getSphone()%></td>
<td><a href="${pageContext.request.contextPath}/ChangeStudent?sno=<%=student.getSno()%>">修改</a>
<a href="${pageContext.request.contextPath}/DelStudent?sno=<%=student.getSno()%>" >删除</a></td>
</tr>
<%
}
%>
</table>
</center>
</body>
</html>
addstudent.jsp
<%--
Created by IntelliJ IDEA.
User: l1957
Date: 2021/2/17
Time: 13:07
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>addstudent</title>
</head>
<body>
<form action= "${pageContext.request.contextPath}/AddStudent" method="post">
<table border="0" width="238" height="252" align="center">
<tr><th colspan="2">添加学生信息</th></tr>
<tr> <td>学号</td> <td><input type="text" id="sno" name="sno"></td> </tr>
<tr> <td>姓名</td> <td><input type="text" id="sname" name="sname"></td> </tr>
<tr> <td>性别</td> <td><input type="text" id="sex" name="sex" ></td> </tr>
<tr> <td>生日</td> <td><input type="text" id="sbirth" name="sbirth"></td> </tr>
<tr> <td>电话</td> <td><input type="text" id="sphone" name="sphone"></td> </tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="提 交">
<input type="reset" value="取 消">
</td>
</tr>
</table>
</form>
</body>
</html>
AddStudentServlet
package com.lqc.servlet;
import com.lqc.factory.DAOFactory;
import com.lqc.vo.Student;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class AddStudentServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//设置编码
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=UTF-8");
//获取前台数据
String sno = req.getParameter("sno");
String sname = req.getParameter("sname");
String sex=req.getParameter("sex");
String sbirth=req.getParameter("sbirth");
String sphone=req.getParameter("sphone");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//封装进JavaBean
Student student=new Student();
student.setSno(Integer.parseInt(sno));
student.setSname(sname);
student.setSex(sex);
try {
student.setSbirth(simpleDateFormat.parse(sbirth));
} catch (ParseException e) {
e.printStackTrace();
}
student.setSphone(sphone);
try {
if(DAOFactory.getIStudentDAOInstance().addStudent(student)){
String forwards="/JSP/student.jsp";
RequestDispatcher df=req.getRequestDispatcher(forwards);
df.forward(req,resp);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
}
效果图
项目地址http://www.atpisher.top:8080/StudentInfo/JSP/index.jsp可以去瞄一眼效果,账号密码,admin,123,源码就不放了,有需要再说吧,太low了。
最后
以上就是知性吐司为你收集整理的javaweb学生信息管理系统(无用版,仅供学习入门)的全部内容,希望文章能够帮你解决javaweb学生信息管理系统(无用版,仅供学习入门)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复