精华内容
下载资源
问答
  • jsp 增删查改例子

    2009-03-13 08:56:01
    jsp mvc增删查改例子...... 学生信息管理
  • JSP serverlet 增删查改

    2011-11-13 14:06:07
    JSP serverlet 增删查改JSP serverlet 增删查改JSP serverlet 增删查改JSP serverlet 增删查改JSP serverlet 增删查改JSP serverlet 增删查改JSP serverlet 增删查改JSP serverlet 增删查改JSP serverlet 增删查改
  • jsp 完成的增删查改页面, ssm 基础的增删查改配件
  • JSP购物车增删查改

    2012-12-19 09:25:20
    JSP购物车增删查改.放入、清空、查看、返回
  • jsp实现增删查改

    2013-06-22 19:24:11
    里面有一个工具类 轻松实现增删查改技术!
  • 实现创建数据库,在web上面展示,实现增删查改,使用mysql数据库,建个表格 实现增删查改,掌握数据库的连接
  • jsp、servlet 实现的增删查改,适合新手入手。使用的是mysql数据库
  • 数字验证登录,实现页面的增删查改,文件下载功能(文件下载没有整合,和增删查改是分开的,都在一个文件下面)
  • 这是有jsp+jdbc+servlet编写的分页,而且带增删查改,采用MVC模式,思路清晰,看代码建立数据库,打开即可运行
  • struts1+jdbc+jsp+sqlserver,增删查改
  • 简易jsp+servlet实现单表增删查改

    万次阅读 多人点赞 2016-10-23 20:15:01
    jsp+servlet进行单表增删查改

    入职一个月了,感觉并没有当初学习时突飞猛进的感觉,公司并没有用到我所学习的ssh框架,在我学了各种springMVC+mybatis框架后仍旧是一头雾水,反正写代码的时候只是把前台页面添加数据,并在springmvc的controller层类中添加相应的方法。想来实在是无所事事,不如学习一下数据结构和算法,并补一补毕向东老师的javase基础视频。

     今天就来自己复习一下当初所学的原生web搭建:jsp+servlet。只要这个没有忘,框架什么的都是浮云(喂,这是在骗自己吗)。

    好了,废话这么多,我们言归正传。首先本项目(这能算项目吗= =)使用到的软件环境有:MyEclipse2014,Tomcat7,数据库:mysql。还有什么待补充。

    补充:本项目需要mysql连接jdbc的jar包,以及jstl的jar包,这里暂不提供下载,请自行百度

    工程整体架构如下图:

    项目架构
















    数据库新建一张名为users的表,此表是参考了此mybatis学习贴

    http://www.cnblogs.com/xdp-gacl/p/4261895.html


     CREATE TABLE users(id INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR(20), age INT);
     INSERT INTO users(NAME, age) VALUES('蕾姆', 17);
     INSERT INTO users(NAME, age) VALUES('艾米莉亚', 17);
    数据库准备工作完成,开始搭建web项目。


    首先,在MyEclipse新建一个web项目。

    然后,依次编写BaseDao(用途是jdbc连接数据库),Users(实体类),UsersDao(接口),UsersDaoImpl(实现类),以及Servlet类:ServletUsers

    然后是前端页面:index.jsp用于展示数据列表。然后还有add.jsp是新增页面,edit.jsp是修改页面。

    BaseDao代码:

    package com.zdf.dao;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    public class BaseDao {
    	public static final String DRIVER = "com.mysql.jdbc.Driver";
    	public static final String URL = "jdbc:mysql://localhost:3306/mybatis";
    	public static final String USER = "root";
    	public static final String PASSWORD = "";
    
    	Connection conn = null;
    	PreparedStatement pstmt = null;
    	ResultSet rs = null;
    
    	public void getConnection() {
    		try {
    			Class.forName(DRIVER);
    			conn = DriverManager.getConnection(URL, USER, PASSWORD);
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
    
    	public int executeUpdate(String sql, Object... obj) {
    		int num = 0;
    		getConnection();
    		try {
    			pstmt = conn.prepareStatement(sql);
    			for (int i = 0; i < obj.length; i++) {
    				pstmt.setObject(i + 1, obj[i]);
    			}
    			num = pstmt.executeUpdate();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		} finally {
    			closeAll();
    		}
    		return num;
    	}
    
    	public ResultSet executeQuery(String sql, Object... obj) {
    		getConnection();
    		try {
    			pstmt = conn.prepareStatement(sql);
    			for (int i = 0; i < obj.length; i++) {
    				pstmt.setObject(i + 1, obj[i]);
    			}
    			rs = pstmt.executeQuery();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		return rs;
    	}
    
    	public void closeAll() {
    		try {
    			rs.close();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		try {
    			pstmt.close();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		try {
    			conn.close();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
    }
    

    UsersDao代码:

    package com.zdf.dao;
    
    import java.util.List;
    
    import com.zdf.entity.Users;
    
    public interface UsersDao {
    	public int addUser(Users u);
    	public int delUser(int id);
    	public int updateUser(Users u);
    	public Users findUserById(int id);
    	public List<Users> getAllUsers();
    }

    UsersDaoImpl代码:

    package com.zdf.dao.impl;
    
    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.zdf.dao.BaseDao;
    import com.zdf.dao.UsersDao;
    import com.zdf.entity.Users;
    
    public class UsersDaoImpl extends BaseDao implements UsersDao {
    
    	Connection conn = null;
    	PreparedStatement pstmt = null;
    	ResultSet rs = null;
    
    	@Override
    	public int addUser(Users u) {
    		int num = 0;
    		String sql = "insert into users(name,age) values(?,?)";
    		try {
    			num = executeUpdate(sql, u.getName(), u.getAge());
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return num;
    	}
    
    	@Override
    	public int delUser(int id) {
    		int num = 0;
    		String sql = "delete from users where id=?";
    		try {
    			num = executeUpdate(sql, id);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return num;
    	}
    
    	@Override
    	public int updateUser(Users u) {
    		int num = 0;
    		String sql = "update users set name=?,age=? where id=?";
    		try {
    			num = executeUpdate(sql, u.getName(), u.getAge(), u.getId());
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return num;
    	}
    
    	@Override
    	public Users findUserById(int id) {
    		Users u = null;
    		String sql = "select * from users where id=?";
    		rs = executeQuery(sql, id);
    		try {
    			if (rs.next()) {
    				u = new Users(rs.getInt(1), rs.getString(2), rs.getInt(3));
    			}
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		return u;
    	}
    
    	@Override
    	public List<Users> getAllUsers() {
    		List<Users> ulist = new ArrayList<Users>();
    		String sql = "select * from users";
    		rs = executeQuery(sql);
    		try {
    			while (rs.next()) {
    				Users u = new Users(rs.getInt(1), rs.getString(2), rs.getInt(3));
    				ulist.add(u);
    			}
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		return ulist;
    	}
    
    }
    

    Users代码:

    package com.zdf.entity;
    
    /**
     * users表所对应的实体类
     */
    public class Users {
    
    	// 实体类的属性和表的字段名称一一对应
    	private int id;
    	private String name;
    	private int age;
    
    	public Users(int id, String name, int age) {
    		this.id = id;
    		this.name = name;
    		this.age = age;
    	}
    
    	public Users() {
    	}
    
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public int getAge() {
    		return age;
    	}
    
    	public void setAge(int age) {
    		this.age = age;
    	}
    
    	@Override
    	public String toString() {
    		return "User [id=" + id + ", name=" + name + ", age=" + age + "]";
    	}
    }
    

    ServletUsers代码:

    package com.zdf.servlet;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    import com.zdf.dao.UsersDao;
    import com.zdf.dao.impl.UsersDaoImpl;
    import com.zdf.entity.Users;
    
    public class ServletUsers extends HttpServlet {
    
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    
    	public void doGet(HttpServletRequest request, HttpServletResponse response)
    			throws ServletException, IOException {
    		doPost(request, response);
    	}
    
    	public void doPost(HttpServletRequest request, HttpServletResponse response)
    			throws ServletException, IOException {
    
    		response.setContentType("text/html;charset=utf-8");
    		request.setCharacterEncoding("utf-8");
    		HttpSession session = request.getSession();
    		PrintWriter out = response.getWriter();
    
    		UsersDao ud = new UsersDaoImpl();
    
    		String dos = request.getParameter("do");
    		if (dos == null || dos.equals("")) {
    			dos = "index";
    		}
    		// 主页
    		if (dos.equals("index")) {
    			List<Users> ulist = ud.getAllUsers();
    			session.setAttribute("ulist", ulist);
    			response.sendRedirect("index.jsp");
    			return;
    		}
    		if (dos.equals("add")) {
    			String name = request.getParameter("name");
    			String ages = request.getParameter("age");
    			int age = Integer.parseInt(ages);
    			Users u = new Users(0, name, age);
    			ud.addUser(u);
    			out.print("<script>alert('新增成功!');window.location='servletusers?do=index';</script>");
    		}
    		if (dos.equals("del")) {
    			String ids = request.getParameter("id");
    			int id = Integer.parseInt(ids);
    			ud.delUser(id);
    			out.print("<script>alert('删除成功!');window.location='servletusers?do=index';</script>");
    			return;
    		}
    		if (dos.equals("editbefore")) {
    			String ids = request.getParameter("id");
    			int id = Integer.parseInt(ids);
    			Users u=ud.findUserById(id);
    			session.setAttribute("edituser", u);
    			response.sendRedirect("edit.jsp");
    			return;
    		}
    		if (dos.equals("edit")) {
    			String ids=request.getParameter("id");
    			int id=Integer.parseInt(ids);
    			String name = request.getParameter("name");
    			String ages = request.getParameter("age");
    			int age = Integer.parseInt(ages);
    			Users u = new Users(id, name, age);
    			ud.updateUser(u);
    			out.print("<script>alert('修改成功!');window.location='servletusers?do=index';</script>");
    			return;
    		}
    	}
    }
    

    web.xml配置(其实并没有写什么东西,注意welcome-file起始页面跳转就可以了,如果你是一路复制过来的,那么这个也要原样复制,因为它包含了servlet类的配置)

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns="http://java.sun.com/xml/ns/javaee"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    	id="WebApp_ID" version="3.0">
    	<display-name>jdbc</display-name>
      <servlet>
        <description>This is the description of my J2EE component</description>
        <display-name>This is the display name of my J2EE component</display-name>
        <servlet-name>ServletUsers</servlet-name>
        <servlet-class>com.zdf.servlet.ServletUsers</servlet-class>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>ServletUsers</servlet-name>
        <url-pattern>/servletusers</url-pattern>
      </servlet-mapping>
    	<welcome-file-list>
    		<welcome-file>servletusers</welcome-file>
    	</welcome-file-list>
    </web-app>

    index.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%
    	String path = request.getContextPath();
    	String basePath = request.getScheme() + "://"
    			+ request.getServerName() + ":" + request.getServerPort()
    			+ path + "/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
    <style type="text/css">
    table {
    	width: 600px;
    	height: 300px;
    }
    td{ text-align:center;}
    </style>
    </head>
    
    <body>
    	<h1>主页</h1>
    	<table border="1px">
    		<tr>
    			<th>id</th>
    			<th>姓名</th>
    			<th>年龄</th>
    			<th>操作</th>
    		</tr>
    		<c:forEach items="${ulist }" var="data">
    			<tr>
    				<td>${data.id }</td>
    				<td>${data.name }</td>
    				<td>${data.age }</td>
    				<td><a href="servletusers?do=editbefore&id=${data.id }">修改</a> <a
    					href="servletusers?do=del&id=${data.id }" οnclick="javascript:return confirm('确认删除吗?');">删除</a></td>
    			</tr>
    		</c:forEach>
    	</table>
    	
    <a href="add.jsp">新增</a>
    </body>
    </html>
    


    add.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'add.jsp' starting page</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
    
      </head>
      
      <body>
        <h1>新增页面</h1>
        <form action="servletusers?do=add" method="post">
        姓名:<input name="name"><br>
        年龄:<input name="age" ><br>
        <input type="submit" value="新增" > <input type="reset">
        </form>
      </body>
    </html>
    

    edit.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'add.jsp' starting page</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
    
      </head>
      
      <body>
        <h1>修改页面</h1>
        <form action="servletusers?do=edit" method="post">
        <input type="hidden" name="id" value="${edituser.id }">
        姓名:<input name="name" value="${edituser.name }"><br>
        年龄:<input name="age" value="${edituser.age }" ><br>
        <input type="submit" value="修改" > <input type="reset">
        </form>
      </body>
    </html>
    

    ok,现在打开浏览器,输入

    http://localhost:8080/jdbc/


    项目就搭建好啦,接下来就测试一下增删改功能是否正确执行了吧!





    展开全文
  • jsp+sqlserver增删查改

    2018-01-06 14:44:26
    ing 写的与数据库的增删改查操作包含多层结构 读取配置文件 关于工厂的运用等都放在其中之后是JDBC等
  • mvc 模式 实现对数据库的增删查改的功能 结构层次清晰mvc 模式 实现对数据库的增删查改的功能 结构层次清晰mvc 模式 实现对数据库的增删查改的功能 结构层次清晰mvc 模式 实现对数据库的增删查改的功能 结构层次清晰...
  • jsp+servlet+bookstrap+mysql实现的人员信息的增删查改管理系统 实现了分页查询跟多条件查询 带数据库
  • 增删查改jsp学习必需掌握的东东,jsp+servlet+javabean MVC
  • easyui实现增删查改

    2019-06-14 19:28:23
    easyui实现增删查改roleInfo.jsproleInfo.jsUserDaoUserAction 在实现增删查改之前,我们先要完成前端的布局,需要使用到easyui的datagrid,dialog,form这三个布局。 roleInfo.jsp <body> <!-- 展示数据 -...


    在实现增删查改之前,我们先要完成前端的布局,需要使用到easyui的datagrid,dialog,form这三个布局。

    roleInfo.jsp

    <body>
    <!-- 展示数据 -->
    <table id="dg"></table>  
    <input type="hidden" id="ctx" value="${pageContext.request.contextPath}">
    <input type="hidden" id="shl" value="11">
    <!-- 弹出框提交表单 -->
    <div id="dd" class="easyui-dialog" title="编辑窗体" style="width:400px;height:200px;"   
            data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true,buttons:'#bb'">   
        <form id="ff" method="post">   
        <input type="hidden" name="SerialNo">
        <div>   
            <label for="uid">uid:</label>   
            <input class="easyui-validatebox" type="text" name="uid" data-options="required:true" />   
        </div>   
         <div>   
            <label for="uname">uname:</label>   
            <input class="easyui-validatebox" type="text" name="uname" data-options="required:true" />   
        </div>   
         <div>   
            <label for="upwd">upwd:</label>   
            <input class="easyui-validatebox" type="text" name="upwd" data-options="required:true" />   
        </div>   
    </form>  
    </div>  
    <div id="bb">
    <a href="#" class="easyui-linkbutton" onclick="ok();">保存</a>
    <a href="#" class="easyui-linkbutton">关闭</a>
    </div>
    </body>
    

    roleInfo.js

    $(function(){
    	$('#dg').datagrid({    
    	    url:$("#ctx").val()+'/userAction.action?methodName=list',    
    	    fitColumns:true,//填充列
    	    fit:true,//填充行
    	    pagination:true,
    	    columns:[[    
    	        {field:'uid',title:'代码',width:100},    
    	        {field:'uname',title:'名称',width:100},    
    	        {field:'upwd',title:'价格',width:100,align:'right'}    
    	    ]]   ,
    	    toolbar: [{
    			iconCls: 'icon-edit',
    			handler: function(){
    				var row=$('#dg').datagrid("getSelected");
    				if(row){
    					$('#shl').val("edit");//设置修改方法的路径
    					$('#ff').form("load",row);
    					$('#dd').dialog("open");
    					alert($('#shl').val());
    				}
    			}
    		},'-',{
    			iconCls: 'icon-add',
    			handler: function(){
    				$('#ff').form("clear");
    				$('#dd').dialog("open");
    				$('#shl').val("add");//设置增加方法的路径
    				$('#dg').datagrid("reload");
    			}
    		},'-',{
    			iconCls: 'icon-remove',
    			handler: function(){
    				var row=$('#dg').datagrid("getSelected");
    				$.ajax({
    					 url:$("#ctx").val()+'/userAction.action?methodName=del&&SerialNo='+row.SerialNo,    
    				     success: function(param){    
    				         $('#dg').datagrid("reload");
    				     } 
    				})
    			}
    		}]
    
    	});  
    })
    //表单提交
    function ok(){
    	$('#ff').form('submit', {    
    	    url:$("#ctx").val()+'/userAction.action?methodName='+$('#shl').val(),    
    	    success: function(param){    
    	        $('#dd').dialog("close");
    	        $('#dg').datagrid("reload");
    	        $('#ff').form("clear");
    	    }    
    	});  
    }
    

    UserDao

    package com.shl.dao;
    
    import java.sql.SQLException;
    import java.util.List;
    import java.util.Map;
    
    import com.shl.util.JsonBaseDao;
    import com.shl.util.JsonUtils;
    import com.shl.util.PageBean;
    import com.shl.util.StringUtils;
    
    public class UserDao extends JsonBaseDao{
    	/**
    	 * 登录查询用户表    登录
    	 * @return
    	 * @throws SQLException 
    	 * @throws IllegalAccessException 
    	 * @throws InstantiationException 
    	 */
    	public List<Map<String, Object>> list(Map<String, String[]> paMap,PageBean pb) throws InstantiationException, IllegalAccessException, SQLException{
    		String sql="select * from t_easyui_user_version2 where true ";
    		String uid=JsonUtils.getParamVal(paMap, "uid");
    		String upwd=JsonUtils.getParamVal(paMap, "upwd");
    		if(StringUtils.isNotBlank(uid)) {
    			sql=sql+" and uid = "+uid;
    		}
    		if(StringUtils.isNotBlank(upwd)) {
    			sql=sql+" and upwd = "+upwd;
    		}
    		return super.executeQuery(sql, pb);
    	}
    	
    	/**
    	 * 通过中间表查询登录用户所对应的权限
    	 * @param paMap
    	 * @param pb
    	 * @return
    	 * @throws InstantiationException
    	 * @throws IllegalAccessException
    	 * @throws SQLException
    	 */
    	public List<Map<String, Object>> listMenu(String uid,PageBean pb) throws InstantiationException, IllegalAccessException, SQLException{
    		String sql="select * from t_easyui_user_version2 where true ";
    		if(StringUtils.isNotBlank(uid)) {
    			sql=sql+" and uid = "+uid;
    		}
    		return super.executeQuery(sql, pb);
    	}
    	
    	/**
    	 * 修改
    	 * @param paMap
    	 * @return
    	 * @throws NoSuchFieldException
    	 * @throws SecurityException
    	 * @throws IllegalArgumentException
    	 * @throws IllegalAccessException
    	 * @throws SQLException
    	 */
    	public int edit(Map<String, String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
    		String sql="update t_easyui_user_version2 set uid=?,uname=?,upwd=? where SerialNo=?";
    		return super.executeUpdate(sql, new String[] {"uid","uname","upwd","SerialNo"}, paMap);
    	}
    	
    	/**
    	 * 删除
    	 * @param paMap
    	 * @return
    	 * @throws NoSuchFieldException
    	 * @throws SecurityException
    	 * @throws IllegalArgumentException
    	 * @throws IllegalAccessException
    	 * @throws SQLException
    	 */
    	public int del(Map<String, String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
    		String sql="delete from t_easyui_user_version2 where SerialNo=?";
    		return super.executeUpdate(sql, new String[] {"SerialNo"}, paMap);
    	}
    	
    	/**
    	 * 增加
    	 * @param paMap
    	 * @return
    	 * @throws NoSuchFieldException
    	 * @throws SecurityException
    	 * @throws IllegalArgumentException
    	 * @throws IllegalAccessException
    	 * @throws SQLException
    	 */
    	public int add(Map<String, String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
    		String sql="insert into t_easyui_user_version2 (uid,uname,upwd) values(?,?,?)";
    		return super.executeUpdate(sql, new String[] {"uid","uname","upwd"}, paMap);
    	}
    }
    

    UserAction

    package com.shl.web;
    
    import java.sql.SQLException;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.fasterxml.jackson.core.JsonProcessingException;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.shl.dao.UserDao;
    import com.shl.util.PageBean;
    import com.shl.util.ResponseUtil;
    import com.zking.framework.ActionSupport;
    
    public class UserAction extends ActionSupport {
    	
    	private UserDao ud=new UserDao();
    	
    	public String login(HttpServletRequest req,HttpServletResponse resp) throws InstantiationException, IllegalAccessException, SQLException {
    		List<Map<String, Object>> list = this.ud.list(req.getParameterMap(), null);
    		if(list!=null&&list.size()>0) {
    			List<Map<String, Object>> listMenu = this.ud.listMenu(req.getParameter("uid"), null);
    			StringBuilder sb=new StringBuilder();
    			for (Map<String, Object> map : listMenu) {
    				sb.append(","+map.get("menuId"));
    			}
    			//,001,002,.....
    			req.setAttribute("menuHid", sb.substring(1));
    		}
    		else {
    			return "login";
    		}
    		return "index";
    	}
    	
    	/**
    	 * datagrid所需数据
    	 * @param req
    	 * @param resp
    	 * @return
    	 * @throws JsonProcessingException
    	 * @throws Exception
    	 */
    	public String list(HttpServletRequest req,HttpServletResponse resp) throws JsonProcessingException, Exception {
    		PageBean pb=new PageBean();
    		pb.setRequest(req);
    		List<Map<String, Object>> list = this.ud.list(req.getParameterMap(), pb);
    		ObjectMapper om=new ObjectMapper();
    		Map<String, Object> map=new HashMap<>();
    		map.put("total", pb.getTotal());
    		map.put("rows", list);
    		ResponseUtil.write(resp, om.writeValueAsString(map));
    		return null;
    	}
    	
    	/**
    	 * form组件提交所需数据(修改)
    	 * @param req
    	 * @param resp
    	 * @return
    	 * @throws JsonProcessingException
    	 * @throws Exception
    	 */
    	public String edit(HttpServletRequest req,HttpServletResponse resp) throws JsonProcessingException, Exception {
    		int edit=this.ud.edit(req.getParameterMap());
    		ObjectMapper om=new ObjectMapper();
    		ResponseUtil.write(resp, om.writeValueAsString(edit));
    		return null;
    	}
    	
    	/**
    	 * 删除
    	 * @param req
    	 * @param resp
    	 * @return
    	 * @throws JsonProcessingException
    	 * @throws Exception
    	 */
    	public String del(HttpServletRequest req,HttpServletResponse resp) throws JsonProcessingException, Exception {
    		int del=this.ud.del(req.getParameterMap());
    		ObjectMapper om=new ObjectMapper();
    		ResponseUtil.write(resp, om.writeValueAsString(del));
    		return null;
    	}
    	
    	/**
    	 * 增加
    	 * @param req
    	 * @param resp
    	 * @return
    	 * @throws JsonProcessingException
    	 * @throws Exception
    	 */
    	public String add(HttpServletRequest req,HttpServletResponse resp) throws JsonProcessingException, Exception {
    		int add=this.ud.add(req.getParameterMap());
    		ObjectMapper om=new ObjectMapper();
    		ResponseUtil.write(resp, om.writeValueAsString(add));
    		return null;
    	}
    }
    

    这样我们的增删查改就完成了
    效果:
    在这里插入图片描述
    在这里插入图片描述

    展开全文
  • jsp servlet 好友系统 增删查改,含分页,分页后排序不变
  • 网页内具体实现了对数据库的增删查改,数据库的连接也非常清晰
  • 这是一个用JSP做的student系统,功能包括增删查改,是考证JSP的最好复习选择.
  • 在web项目中利用dom实现xml的增删查改,数据源直接采用xml实现,登录界面利用jsp实现(美观)
  • ok.jsp(增删查改)

    2016-06-19 21:53:41
    pageEncoding="UTF-8"%> Insert title here  OK    添加    修改      序号  姓名  班级
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
            OK
            
            <a href="${pageContext.request.contextPath}/index_cdAddPage.action">添加</a>
            <input type="button" value="删除" οnclick="doDelete()">
            <a href="#" οnclick="updateProd()">修改</a>
            <table>
                <tr>
                    <th>序号</th>
                    <th>姓名</th>
                    <th>班级</th>
                    <!-- <td><a href="#" οnclick="selOrUnSel(this)">全选</a></td>  
                    <input type="button" id="othercheck" value="反选"/>-->
                    <td><a href="#" οnclick="SelectAll()">全选/反选</a></td>
                </tr>
                
                <s:iterator value="#request.list" var="s">
                <tr>
                    <td>${s.id}</td><!-- <s:property value="id"/> -->
                    <td>${s.name}</td><!--<s:property value="s.name"/> -->
                    <td>${s.className}</td><!--   -->
                    <!-- <td>
                        <input type="checkbox" id="seltId" value="?????????????"/>
                    </td> -->
                    <td><input name="checkboxid" type="checkbox" value="${s.id}"></td>
                </tr>
                </s:iterator>
                
            </table>
            <script type="text/javascript">
            function SelectAll() {
                 var checkboxs=document.getElementsByName("checkboxid");
                 for (var i=0;i<checkboxs.length;i++) {
                  var e=checkboxs[i];
                   e.checked=!e.checked;
                   /* if(e.checked==true){
                      e.checked=false;
                  }
              else{
                  e.checked=true
                  }*/
                 }
                }
            function selOrUnSel(obj){
                if(obj.innerText=="全选"){
                    obj.innerText="全不选";
                    $(":checkbox").attr("checked",true);
                }else{
                    obj.innerText="全选";
                    $(":checkbox").attr("checked",false);
                }
            }
            function doDelete(){
                if(confirm("你确定要删除吗?")){
                    var param=$(":checkbox:checked").serialize();
                    location.href="index_deleteStudents?"+param;
                }
            }
            
            function updateProd(){
                var obj=$(":checkbox:checked");
                if(obj.length==0){
                    alert("请选择要修改的");
                    return;
                }
                if(obj.length>1){
                    alert("一次只能修改一个");
                    return;
                }
                location.href="index_cdUpdatePage.action?checkboxid="+obj[0].value;
                
            }

            </script>
                
                
            
    </body>
    </html>
    展开全文
  • jsp+JavaBean+Oracle实现表的增删查改,
  • jsp作业,自己用jsp+myeclipse+mysql做的学生成绩管理系统,实现登录界面和增删查改,有数据库
  • servlet jsp一套完整的增删查改思路

    千次阅读 2017-07-26 13:41:37
    然后就用servlet写了一套小的增删查改,写出来做一个笔记,当然能帮助更多初学者解惑更好,由于是初学,肯定还有很多地方不足和缺陷,希望大家帮我指出来,一起讨论,牛大哥请多指教! 写增查删改步骤: 注:很多servlet我都...

    小弟刚刚学了servlet.然后就用servlet写了一套小的增删查改,写出来做一个笔记,当然能帮助更多初学者解惑更好,由于是初学,肯定还有很多地方不足和缺陷,希望大家帮我指出来,一起讨论,牛大哥请多指教!

    写增查删改步骤:
    注:很多servlet我都改映射了 mapping
    写之前的连接数据库准备以及如何创建项目:
    1:先设计需求(学号,姓名,性别,....)学号一般用序列;
    设计数据库
    2:创建eclipse的Dynamic Web Project项目(动态Web项目);
    3:导入oracle的JDBC jar包(存放目录:D:\app\Administrator\product\11.2.0\dbhome_1\jdbc\lib下的


    ojdbc6.jar)然后放在刚才创建的动态Web项目下的WebContent文件夹下的WEB-INF下的lib文件夹里,放进去后Web 


    App Libraries会自动生成一个ojdbc6.jar的jar包;
    4:以上步骤进行完后开始写代码.


    1):增加:
    1:先在WebContent文件夹下创建jsp文件,用来写一个显示表单以便于录入信息
    如下:
    <body>
    <form action="StudentAddServlet" method="post">
    <table>
    <tr>
    <td>姓名</td>
    <td><input type="text" name="STUNAME"></td>
    </tr>
    <tr>
    <td>性别</td>
    <td>
    <input type="radio" name="sex" value="0">女
    <input type="radio" name="sex" value="1">男
    </td>
    </tr>
    <tr>
    <td>生日</td>
    <td><input type="type" name="birth"></td>
    </tr>
    <tr>
    <td>专业</td>
    <td><select name="PROFESSIONAL">
    <option value="1">11111111</option>
    <option value="2">22222222</option>
    <option value="3">33333333</option>
    </select>

    </td>
    </tr>
    <tr>
    <td>爱好</td>
    <td>
    <input type="checkbox" name="love" value="上刀山">上刀山
    <input type="checkbox" name="love" value="下火海">下火海
    </td>
    </tr>
    <tr>
    <td>个人说明</td>
    <td><textarea rows="5" cols="30"  name="memo"></textarea></td>
    </tr>
    <tr >
    <td colspan="2">
    <input type="submit" value="提交">
    <input type="reset" value="重置">
    </td>
    </tr>

    </table>
    </form>
    2:再写一个Student类,然后封装,(set,get方法),
    3连接数据库DBUtil
    4:写一个增方法,传参,传入一个对象,(因为下一步要用servlet获得的数据往Student类里面set数据,然后传入对象,


    直接get出来就是jsp传过来的数据);
    代码如下:
    public Integer Add(Student stu){
    DBUtil dbu=new DBUtil();
    String sql="insert into SERSTUDENT(STUID,STUNAME,SEX,BIRTH,PROFESSIONAL,LOVE,MEMO) 


    values(SER_STU.NEXTVAL,?,?,?,?,?,?)";
    try {
    PreparedStatement pstmt=dbu.getConn().prepareStatement(sql);
    pstmt.setString(1, stu.getStuName());
    pstmt.setInt(2, stu.getSex());
    pstmt.setString(3, null);
    pstmt.setString(4, stu.getProfessional());
    pstmt.setString(5, stu.getLove());
    pstmt.setString(6, stu.getMemo());
    return pstmt.executeUpdate();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return 0;
    }
    5:写一个Servlet类,用servlet把jsp写的name用request.parameter("name")方法获取出来:如:String 


    stuName=request.getParameter("STUNAME");
    然后先实例化一个Student对象stu,用stu.setXXX方法往对应的变量里set值,然后把这个对象传到增方法里


    studentdao.Add(stu),上一步Add方法是需要传参数的,所以这里直接传入一个对象,这样set进去的值就传到add方法


    里了,add直接get出来就可以用,具体代码如下:protected void doPost(HttpServletRequest request, 


    HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    request.setCharacterEncoding("utf-8");
    String stuName=request.getParameter("STUNAME");
    String Sex=request.getParameter("sex");
    String Birth=request.getParameter("birth");
    String Professional=request.getParameter("PROFESSIONAL");
    String[] Love=request.getParameterValues("love");//love是爱好,由于爱好的值是CheckBox,


    复选框,所以要获取一个数组;
    String Memo=request.getParameter("memo");
    Student stu=new Student();
    stu.setStuName(stuName);
    stu.setSex(Integer.parseInt(Sex));
    stu.setBirth(Birth);
    stu.setProfessional(Professional);
    StringBuffer stringbuffer=new StringBuffer();
    for (String string : Love) {//把这个数组用StringBuffer遍历出来;
    stringbuffer.append(string).append(",");
    }
    stu.setLove(stringbuffer.toString());
    stu.setMemo(Memo);
    StudentDao studentdao=new StudentDao();//这是类的名字,先实例化对象;
    studentdao.Add(stu);//然后调用实例化的方法.Add;
    response.sendRedirect("StudentListServlet");// 代码执行完后会跳转到查询详细信息的列



    }
    注:response.sendRedirect("StudentListServlet");是一个跳转方法,就是执行完后会跳转到StudentListServlet,


    由于现在暂时还没有写到查询表,所以这个时候会404,也就是找不到页面.
    一个增的功能基本实现了.接下来就是实现查询的功能.


    2):查询,查询就是把值从数据库里取出来,在一个table表格里面显示出来,思路:把从数据库里遍历出来,然后


    把"Student" new一个对象,这个对象也得放在ResultSet.next()方法里遍历,这时候每完成一个学生的遍历就会把一


    个学生new一个对象,把这些对象放到一个List里面,然后把这个List放到jsp页面写好的table里面遍历出来,然后一


    个查询表格就展出来了.具体如下:
    1:先写一个查询的方法,返回一个数组,以便于下面用数组接收这个方法返回的数组,具体代码如下:
    public List<Student> list(Student student){
    List<Student> list=new ArrayList<Student>();
    DBUtil dbu=new DBUtil();
    String sql="select * from SERSTUDENT";
    try {
    PreparedStatement pstate=dbu.getConn().prepareStatement(sql);
    ResultSet rs = pstate.executeQuery();

    while(rs.next()){
    Student stu =new Student();
    try {
    stu.setStuId(rs.getString(1));
    stu.setStuName(rs.getString(2));
    stu.setSex(rs.getInt(3));
    stu.setBirth(rs.getString(4));
    stu.setProfessional(rs.getString(5));
    stu.setLove(rs.getString(6));
    stu.setMemo(rs.getString(7));
    list.add(stu);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return list;

    }
    2:然后写一个Servlet,先把上面的对象实例化,然后调用list方法,由于我们的list方法是返回一个List数组,所以我


    们调用这个方法的时候需要写new一个list接收,然后把接收到的list用request.setAtttibute("list",list) name


    为"list",value为list,然后我们把这个list用getRequestDispatcher("index.jsp")跳转到需要展示的jsp页面,(暂


    时没有写,下一步就写)用forward方法转发(request, response).代码如下:
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws 


    ServletException, IOException {
    StudentDao studentdao=new StudentDao();
    List<Student> list=studentdao.list(null);//因为上一步我写的list方法需要传参,但是现在


    用不到传参,就传个null;
    request.setAttribute("list", list);
    request.getRequestDispatcher("index.jsp").forward(request, response);
    }


    3:写一个展示页面,index.jsp把刚才setAttribute的list用list接收出来List<Student> list=(List<Student>)


    request.getAttribute("list"),然后遍历出来foreach for(Student Student:list),具体代码如下:
    <body>
    <a href="Students.jsp">添加</a>
    <table border="1">


    <tr>
    <th>学号</th>
    <th>姓名</th>
    <th>性别</th>
    <th>生日</th>
    <th>专业</th>
    <th>爱好</th>
    <th>个人说明</th>
    </tr>
    <%
    List <Student> list=(List <Student>)request.getAttribute("list");
    for(Student student:list){
    %>
    <tr>
    <td><%=student.getStuId() %></td>
    <td><%=student.getStuName() %></td> 
    <td><%=student.getSex() %></td>
    <td><%=student.getBirth()%></td>
    <td><%=student.getProfessional()%></td>
    <td><%=student.getLove() %></td>
    <td><%=student.getMemo() %></td>
    </tr>
    <% }%>
    </table>
    </body>




    3)删,
    1:删除就是在数据查询出来后,根据数据的唯一键的value进行删除,因为SQL语句结构是:"selete 表 where 唯一键


    =?"又因为学号是序列,所以把学号设置成唯一键,删的时候就where学号
    2:因为上一步已经把学号遍历出来了,所以在后面加一个往sevelet传stuId的值的跳转链接就能顺利取到我们SQL需


    要用到where唯一键=?,也就是where stuId=? 
    3:先写一个删除方法:传入一个对象参数,主要是用这个对象的getStuId的值;
    public Integer delete(Student student){
    DBUtil dbu=new DBUtil();

    String sql="delete SERSTUDENT where stuId=?";
    try {
    PreparedStatement pstmt=dbu.getConn().prepareStatement(sql);
    pstmt.setString(1,student.getStuId());
    return pstmt.executeUpdate();
    } catch (NumberFormatException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return 0;
    }
    4:这时候我们还得从表格里把stuId传到删除方法里面然后就能正常删除了,也就是在刚才的查询的表里加一个操作,


    删除和修改,点击删除的时候就传到servlet里stuId值
    5:也就是在后面加一个<td><a href="Delete?stuId=student.getStuId()">删除</a></td>
    6:写一个servlet 先把stuId的值接收过来,用request.getAttribute("stuId");方法接收,然后先实例化对


    象,StudentDao studentdao=new StudentDao();然后把获得的stuId的值set到Student类里面,
    然后调用studentdao.delete("Student类"),就能删除了
    7:但是这样操作不太友好,没有提示,不能防止误操作,所以我们写一个小脚本,在脚本里传参进行删除:
    <Script type="text/javascript">
    function del(stuId){
    if(confirm("确定要删除吗?")){
    Window.location.href="Delete?stuId"+stuId//重定向到"Delete"传值为 "stuId" 值为传入的产参数


    stuId
    }
    }
    </Script>
    然后下面直接调用函数<a JavaScript:del(<%=student.getStuId()%>)">
    6:具体代码如下:
    <html>


    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>详细信息</title>
    <script type="text/javascript">
    function del(stuId){
    if(confirm("确定要删除吗?")){//这个是提示窗口,确定要删除吗?点击是就删除了,点击否就取消了.
    window.location.href="Delect?stuId="+stuId;
    }
    }
    </script>
    </head>
    <body>
    <a href="Students.jsp">添加</a>
    <table border="1">


    <tr>
    <th>学号</th>
    <th>姓名</th>
    <th>性别</th>
    <th>生日</th>
    <th>专业</th>
    <th>爱好</th>
    <th>个人说明</th>
    <th>操作</th>
    </tr>
    <%/* StudentDao studentdao=new StudentDao();
    List<Student> list=studentdao.list(null); */
    List <Student> list=(List <Student>)request.getAttribute("list");
    for(Student student:list){
    %>
    <tr>
    <td><%=student.getStuId() %></td>
    <td><%=student.getStuName() %></td> 
    <td><%=student.getSex() %></td>
    <td><%=student.getBirth()%></td>
    <td><%=student.getProfessional()%></td>
    <td><%=student.getLove() %></td>
    <td><%=student.getMemo() %></td>
    <td><a href="Javascript:del(<%=student.getStuId()%>)">删除</a>|<a href="Update?stuId=<


    %=student.getStuId()%>&method=select">修改</td>
    </tr>
    <% }%>
    </table>
    </body>
    </html>




    4):修改:

    1:修改也是先在查询的jsp表格里插入一个操作,上面的代码里已经插入了.
    2:我们得写一个修改的页面表单,跟添加数据的表单页面差不多,但是得用value把表单都赋值,赋需要修改的所有属


    性,也就是单条查询数据,然后把查询到的数据传到到Update.jsp的修改表单里.
    jsp表单代码如下:
    <form action="" method=post>
    <table>
    <tr>
    <td>姓名</td>
    <td>
    <input type="hidden" name="stuId" value="<%=stu.getStuId()%>">
    <input type="text" name="STUNAME" value="<%=stu.getStuName() %>" >
    </td>
    </tr>
    <tr>
    <td>性别</td>
    <td>
    <input type="radio" name="sex" value="0" <%if(0==stu.getSex())


    {out.print("checked"); } %>>女
    <input type="radio" name="sex" value="1" <%if(1==stu.getSex())


    {out.print("checked"); } %>>男
    </td>
    </tr>
    <tr>
    <td>生日</td>
    <td><input type="text" name="birth"></td>
    </tr>
    <tr>
    <td>专业</td>
    <td><select name="PROFESSIONAL">
    <option value="1" <%if("1".equals(stu.getProfessional()))


    {out.print("checked");} %>>11111111</option>
    <option value="2" <%if("2".equals(stu.getProfessional()))


    {out.print("checked");} %>>22222222</option>
    <option value="3" <%if("3".equals(stu.getProfessional()))


    {out.print("checked");} %>>33333333</option>
    </select>

    </td>
    </tr>
    <tr>
    <td>爱好</td>
    <td>
    <input type="checkbox" name="love" value="上刀山">上刀山
    <input type="checkbox" name="love" value="下火海">下火海
    </td>
    </tr>
    <tr>
    <td>个人说明</td>
    <td><textarea rows="5" cols="30"  name="memo"></textarea></td>
    </tr>
    <tr >
    <td colspan="2">
    <input type="submit" value="提交">
    <input type="reset" value="重置">
    </td>
    </tr>
    </table>
    </form>
    3:再写一个单条查询的方法queryById(String stuId);
    代码如下:
    public Student queryById(String stuId){
    DBUtil dbu=new DBUtil();
    Student stu =new Student();
    String sql="select * from SERSTUDENT where stuId=?";
    try {
    PreparedStatement pstate=dbu.getConn().prepareStatement(sql);
    pstate.setString(1, stuId);
    ResultSet rs = pstate.executeQuery();
    while(rs.next()){
    try {
    stu.setStuId(rs.getString(1));
    stu.setStuName(rs.getString(2));
    stu.setSex(rs.getInt(3));
    stu.setBirth(rs.getString(4));
    stu.setProfessional(rs.getString(5));
    stu.setLove(rs.getString(6));
    stu.setMemo(rs.getString(7));
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    rs.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return stu;

    }
    4:再写一个servletUpdate类
    {
    String stuId=request.getParameter("stuId");


    StudentDao studao=new StudentDao();
    Student stu= studao.queryById(stuId);
    request.setAttribute("stu", stu);
    request.getRequestDispatcher("Update.jsp").forward(request,response);
    }
    5:上面的修改按钮已经写过了"<a href="Update?stuId=<%=student.getStuId()%>&method=select">"然后点击查询


    表的修改按钮就会把stuId的值传到单条查询方法里,然后request.getRequestDispatcher("Update.jsp").forward


    (request,response)就会跳转到Update.jsp即把值传到了表里,然后可以重新写表单的值,点提交再提交到


    action="Update?method=update"处理,这个处理就是修改数据库查出来的单条数据,action="Update?


    method=update" 这句是往Updateservlet再传入一个名字为method,值为update的变量,然后在servlet里if


    ("update".equals(method))就执行修改,else if("select".equals(method))就执行查询方法
    6:修改方法:
    public Integer Update(Student stu){
    DBUtil dbu=new DBUtil();
    String sql="update SERSTUDENT set 


    STUNAME=?,SEX=?,BIRTH=?,PROFESSIONAL=?,LOVE=?,MEMO=? where STUID=?" ;
    try {
    PreparedStatement pstmt=dbu.getConn().prepareStatement(sql);
    pstmt.setString(1, stu.getStuName());
    pstmt.setInt(2, stu.getSex());
    pstmt.setString(3, null);
    pstmt.setString(4, stu.getProfessional());
    pstmt.setString(5, stu.getLove());
    pstmt.setString(6, stu.getMemo());
    pstmt.setString(7, stu.getStuId());
    return pstmt.executeUpdate();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return 0;
    }
    7:servlet代码如下:
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws 


    ServletException, IOException {
    // TODO Auto-generated method stub
    request.setCharacterEncoding("utf-8");
    String method=request.getParameter("method");
    if("update".equals(method)){

    String stuId=request.getParameter("stuId");
    String stuName=request.getParameter("STUNAME");
    String Sex=request.getParameter("sex");
    String Birth=request.getParameter("birth");
    String Professional=request.getParameter("PROFESSIONAL");
    String[] Love=request.getParameterValues("love");
    String Memo=request.getParameter("memo");
    System.out.println("if"+stuId);
    Student stu=new Student();
    stu.setStuId(stuId);
    stu.setStuName(stuName);
    stu.setSex(Integer.parseInt(Sex));
    stu.setBirth(Birth);
    stu.setProfessional(Professional);
    StringBuffer stringbuffer=new StringBuffer();
    for (String string : Love) {
    stringbuffer.append(string).append(",");
    }
    stu.setLove(stringbuffer.toString());
    stu.setMemo(Memo);
    StudentDao studentdao=new StudentDao();
    studentdao.Update(stu);
    response.sendRedirect("StudentListServlet");
    }
    else if("select".equals(method)){
    String stuId=request.getParameter("stuId");


    StudentDao studao=new StudentDao();
    Student stu= studao.queryById(stuId);
    request.setAttribute("stu", stu);
    request.getRequestDispatcher("Update.jsp").forward(request,response);
    }
    }
    }

    展开全文
  • Jsp+Servlet+JDBC+ Mysql 增删查改 项目结构 1.数据库 -- 创建数据库 create database readjava_study CHARACTER SET utf8 COLLATE utf8_general_ci; -- 创建学生信息表 CREATE TABLE `student` ( `...
  • 基于jsp完成的分页查询的增删查改 jsp页面 第一页代码: userpage: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri=...
  • 基于JSP+JavaBean+Servlet+Ajax+Mysql的增删查改完整例子,ajax异步检测验证码,数据库是否存在
  • 相当于数据库命令的 增删查改  相当于三层架构的(DB层) 7 zhu.jdbc.unit 存放系统的通用工具类,提供给【数据访问层】、【业务处理层】、【DB层】来使用   8 zhu.jdbc...
  • jsp作业,自己用jsp+myeclipse+mysql做的学生成绩管理系统,实现登录界面和增删查改,有数据库

空空如也

空空如也

1 2 3 4 5 ... 17
收藏数 328
精华内容 131
关键字:

jsp增删查改