当前位置: 首页 > wzjs >正文

网站建设前台后台论坛购物网站开发

网站建设前台后台,论坛购物网站开发,太原建设北路小学网站,网站的pv uv1.创建表t_student,其中包含学号stuno,姓名stuname,性别stusex三个字段,在表中插入一些测试数据。 2.实现下述功能: 编写显示所有学生资料信息页面,其中包含一个表单用来根据学生姓…

1.创建表t_student,其中包含学号stuno,姓名stuname,性别stusex三个字段,在表中插入一些测试数据。

2.实现下述功能:

  1. 编写显示所有学生资料信息页面,其中包含一个表单用来根据学生姓名模糊查询匹配的学生信息。
  2. 在学生信息后面增加一个“删除学生信息”链接,单击链接可以将学生信息从数据库中删除,然后跳转到显示所有学生资料信息页面
  3. 部分代码:

package com.lab.model;

public class Student {

    private String stuno;

    private String stuname;

    private String stusex;

    public Student() {

    }

    public Student(String stuno, String stuname, String stusex) {

        this.stuno = stuno;

        this.stuname = stuname;

        this.stusex = stusex;

    }

    public String getStuno() {

        return stuno;

    }

    public void setStuno(String stuno) {

        this.stuno = stuno;

    }

    public String getStuname() {

        return stuname;

    }

    public void setStuname(String stuname) {

        this.stuname = stuname;

    }

    public String getStusex() {

        return stusex;

    }

    public void setStusex(String stusex) {

        this.stusex = stusex;

    }

    @Override

    public String toString() {

        return "Student [stuno=" + stuno + ", stuname=" + stuname + ", stusex=" + stusex + "]";

    }

}

package com.lab.dao;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;

import com.lab.model.Student;

import com.lab.util.DatabaseBean;

public class StudentDao {

    public List<Student> queryAllStudents() {

        List<Student> students = new ArrayList<>();

        String sql = "select * from t_student";

        try (Connection conn = DatabaseBean.getConnection();

             PreparedStatement psmt = conn.prepareStatement(sql);

             ResultSet rs = psmt.executeQuery()) {

            while (rs.next()) {

                Student stu = new Student();

                stu.setStuno(rs.getString("stuno"));

                stu.setStuname(rs.getString("stuname"));

                stu.setStusex(rs.getString("stusex"));

                students.add(stu);

            }

        } catch (SQLException e) {

            e.printStackTrace();

        }

        return students;

    }

    public List<Student> queryAllStudents(String stuname) {

        List<Student> students = new ArrayList<>();

        String sql = "select * from t_student where stuname like?";

        try (Connection conn = DatabaseBean.getConnection();

             PreparedStatement psmt = conn.prepareStatement(sql)) {

            psmt.setString(1, "%" + stuname + "%");

            try (ResultSet rs = psmt.executeQuery()) {

                while (rs.next()) {

                    Student stu = new Student();

                    stu.setStuno(rs.getString("stuno"));

                    stu.setStuname(rs.getString("stuname"));

                    stu.setStusex(rs.getString("stusex"));

                    students.add(stu);

                }

            }

        } catch (SQLException e) {

            e.printStackTrace();

        }

        return students;

    }

    public boolean deleteStudent(String stuno) {

        String sql = "delete from t_student where stuno=?";

        try (Connection conn = DatabaseBean.getConnection();

             PreparedStatement psmt = conn.prepareStatement(sql)) {

            psmt.setString(1, stuno);

            int result = psmt.executeUpdate();

            return result > 0;

        } catch (SQLException e) {

            e.printStackTrace();

            return false;

        }

    }

    public boolean addStudent(Student stu) {

        String sql = "insert into t_student values(?,?,?)";

        try (Connection conn = DatabaseBean.getConnection();

             PreparedStatement psmt = conn.prepareStatement(sql)) {

            psmt.setString(1, stu.getStuno());

            psmt.setString(2, stu.getStuname());

            psmt.setString(3, stu.getStusex());

            int result = psmt.executeUpdate();

            return result > 0;

        } catch (SQLException e) {

            e.printStackTrace();

            return false;

        }

    }

    public boolean updateStudent(Student stu) {

        String sql = "update t_student set stuname=?,stusex=? where stuno=?";

        try (Connection conn = DatabaseBean.getConnection();

             PreparedStatement psmt = conn.prepareStatement(sql)) {

            psmt.setString(1, stu.getStuname());

            psmt.setString(2, stu.getStusex());

            psmt.setString(3, stu.getStuno());

            int result = psmt.executeUpdate();

            return result > 0;

        } catch (SQLException e) {

            e.printStackTrace();

            return false;

        }

    }

    public Student queryStudent(String stuno) {

        Student stu = null;

        String sql = "select * from t_student where stuno=?";

        try (Connection conn = DatabaseBean.getConnection();

             PreparedStatement psmt = conn.prepareStatement(sql)) {

            psmt.setString(1, stuno);

            try (ResultSet rs = psmt.executeQuery()) {

                if (rs.next()) {

                    stu = new Student();

                    stu.setStuno(rs.getString("stuno"));

                    stu.setStuname(rs.getString("stuname"));

                    stu.setStusex(rs.getString("stusex"));

                }

            }

        } catch (SQLException e) {

            e.printStackTrace();

        }

        return stu;

    }

}

package com.lab.util;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

public class DatabaseBean {

    public static Connection getConnection() {

        Connection conn = null;

        try {

            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

            String path = "C:/Users/李心洁/Documents/Database6.accdb";

            String url = "jdbc:ucanaccess://" + path;

            conn = DriverManager.getConnection(url);

        } catch (ClassNotFoundException e) {

            e.printStackTrace();

        } catch (SQLException e) {

            e.printStackTrace();

        }

        return conn;

    }

    public static void close(ResultSet rs, PreparedStatement psmt, Connection conn) {

        try {

            if (rs!= null) {

                rs.close();

            }

            if (psmt!= null) {

                psmt.close();

            }

            if (conn!= null) {

                conn.close();

            }

        } catch (SQLException e) {

            e.printStackTrace();

        }

    }

}

package com.lab.action;

import javax.servlet.ServletContext;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;

import org.apache.struts2.interceptor.ServletResponseAware;

import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;

public class SuperAciton extends ActionSupport implements ServletRequestAware, ServletResponseAware, ServletContextAware {

    private static final long serialVersionUID = 1L;

    protected HttpServletRequest request;

    protected HttpServletResponse response;

    protected HttpSession session;

    protected ServletContext application;

    @Override

    public void setServletContext(ServletContext application) {

        this.application = application;

    }

    @Override

    public void setServletResponse(HttpServletResponse response) {

        this.response = response;

    }

    @Override

    public void setServletRequest(HttpServletRequest request) {

        this.request = request;

        this.session = request.getSession();

    }

}

package com.lab.action;

import java.util.List;

import com.lab.dao.StudentDao;

import com.lab.model.Student;

public class StudentAction extends SuperAciton {

    private StudentDao studentDao = new StudentDao();

    public String find() {

        List<Student> students = studentDao.queryAllStudents();

        request.setAttribute("students", students);

        return "find_success";

    }

    public String query() {

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

        List<Student> students = studentDao.queryAllStudents(stuname);

        request.setAttribute("students", students);

        return "query_success";

    }

    public String delete() {

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

        studentDao.deleteStudent(stuno);

        return "delete_success";

    }

    public String add() {

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

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

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

        Student stu = new Student(stuno, stuname, stusex);

        boolean flag = studentDao.addStudent(stu);

        if (flag) {

            return "add_success";

        } else {

            return "add_failure";

        }

    }

    public String update() {

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

        Student student = studentDao.queryStudent(stuno);

        request.setAttribute("student", student);

        return "update_success";

    }

    public String save() {

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

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

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

        Student stu = new Student(stuno, stuname, stusex);

        boolean flag = studentDao.updateStudent(stu);

        if (flag) {

            return "save_success";

        } else {

            return "save_failure";

        }

    }

}

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

        pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>首页面</title>

</head>

<body>

    首页面

    <a href="find.action">查询所有学生数据</a>

</body>

</html>

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

        pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>查询所有学生数据</title>

</head>

<body>

    <form action="query.action" method="get">

        请输入要查询的学生姓名(支持模糊查询) <input type="text" name="stuname"

                                              placeholder="学生姓名"> <input type="submit" value="查询">

    </form>

    <table>

        <tr>

            <td>学号</td>

            <td>姓名</td>

            <td>性别</td>

            <td>操作</td>

        </tr>

        <c:forEach items="${students }" var="stu">

            <tr>

                <td>${stu.stuno }</td>

                <td>${stu.stuname }</td>

                <td>${stu.stusex }</td>

                <td><a href="delete.action?stuno=${stu.stuno }">删除</a> <a

                        href="update.action?stuno=${stu.stuno }">修改</a></td>

            </tr>

        </c:forEach>

    </table>

    <a href="student_add.jsp">添加学生数据</a>

</body>

</html>

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

        pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>添加学生数据</title>

</head>

<body>

    <form action="add.action" method="post">

        学号: <input type="text" name="stuno" required><br>

        姓名: <input type="text" name="stuname" required><br>

        性别: <input type="text" name="stusex" required><br>

        <input type="submit" value="添加">

    </form>

</body>

</html>

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

        pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>修改学生数据</title>

</head>

<body>

    <form action="save.action" method="post">

        <input type="hidden" name="stuno" value="${student.stuno }">

        姓名: <input type="text" name="stuname" value="${student.stuname }" required><br>

        性别: <input type="text" name="stusex" value="${student.stusex }" required><br>

        <input type="submit" value="保存">

    </form>

</body>

</html>

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

        "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <package name="default" namespace="/" extends="struts-default">

        <default-action-ref name="index" />

        <action name="index">

            <result>index.jsp</result>

        </action>

        <action name="*" class="com.lab.action.StudentAction" method="{1}">

            <result name="find_success">student_find.jsp</result>

            <result name="query_success">student_find.jsp</result>

            <result name="delete_success" type="redirectAction">find</result>

            <result name="add_success" type="redirectAction">find</result>

            <result name="add_failure" type="redirect">student_add.jsp</result>

            <result name="update_success">student_update.jsp</result>

            <result name="save_success" type="redirectAction">find</result>

            <result name="save_failure" type="chain">update</result>

        </action>

    </package>

</struts>

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

    <display-name>StudentManagement</display-name>

    <filter>

        <filter-name>struts2</filter-name>

        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

    </filter>

    <filter-mapping>

        <filter-name>struts2</

 

 

http://www.dtcms.com/wzjs/537590.html

相关文章:

  • 网站双倍浮动百度推广哪家做的最好
  • 网站中图片怎么做的移动端ui设计是什么
  • 网站怎么做团购网站建设落地页
  • 文本资料分享网站 建设dede制作的网站挂马
  • 漳州网站开发去博大钱少awordpress新手教程
  • 网站开发前端框架和后端框架网站建设 浏览器兼容
  • 企业网站建设的缺点重庆市建设工程信息网打不开是怎么回事
  • 廊坊建设局网站6jsp网站开发怎么调试
  • 百度的企业网站诸城手机网站建设
  • 三更app下载网站百度问一问官网
  • 石家庄网络营销网站推广网站建设死人接单
  • 天长网站seovue.js合作做网站么
  • 网站怎么排名wordpress会员权限
  • 版面设计素材网站郑州做网站的外包公司
  • 网站服务器容器免费资源部落wordpress
  • 房产网站关键词优化python基础教程电子书下载
  • 本地建设网站宁阳网站开发
  • 网站改版什么意思wordpress mysql用户名密码
  • 保山专业的网站建设网站自己建设
  • 做的网站在不同浏览器不能上传图片到网站
  • 网站托管 域名苏州网站开发公司济南兴田德润地址
  • 白银区住房和城乡建设局网站有网站源码怎么上传
  • 如何编程做网站设计师网址导航官网
  • 中国建设银行国际互联网网站沈阳做网站的地方
  • 门网站制作网站建设方案平台
  • 淘宝导购网站模版网络设计报告怎么写
  • 全世界做会展介绍的网站排名网页布局的设计步骤
  • 宁波免费建站外包公司品牌广告投放
  • 深圳做网站的地方购买域名要多少钱
  • 长沙网站建设模板软件开发工资一般多少深圳