也是只帖代码。。。。不讲解。

1、search.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 'find.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>
<form action="goodsServlet">
商品名:<input type="text" name="goodsName"/><br/>
商品类型:<input type="text" name="goodsType"/><br/>
<input type="hidden" value="findAll" name="status"/>
<input type="submit" value="查询"/>
</form>
</body>
</html>

2、show.jsp

<%@ page language="java" import="java.util.*,java.sql.*" 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 'show.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">
--> <script type="text/javascript">
function delGoods(no){
window.location.href="goodsServlet?no="+no+"&status=delete&goodsName=<%=request.getParameter("goodsName")%>&goodsType=<%=request.getParameter("goodsType")%>";
} function editGoods(no){
window.location.href="goodsServlet?no="+no+"&status=edit&goodsName=<%=request.getParameter("goodsName")%>&goodsType=<%=request.getParameter("goodsType")%>";
}
</script> </head> <body>
<table border="1" cellpadding="0" cellspacing="0" width="600">
<tr>
<td>商品编号</td>
<td>商品名</td>
<td>生产日期</td>
<td>地址</td>
<td>商品类型</td>
<td>操作</td>
</tr> <%
ResultSet rs = (ResultSet)request.getAttribute("rs");
while(rs.next()){
%>
<tr>
<td><%=rs.getString("no") %></td>
<td><%=rs.getString("name") %></td>
<td><%=rs.getString("time") %></td>
<td><%=rs.getString("address") %></td>
<td><%=rs.getString("type") %></td>
<td>
<input type="button" value="删除" onclick="delGoods('<%=rs.getString("no") %>')"/>
<input type="button" value="修改" onclick="editGoods('<%=rs.getString("no") %>')"/>
</td>
</tr>
<%
}
%>
</table>
</body>
</html>

3、showEdit.jsp

<%@ page language="java" import="java.util.*,java.sql.*" 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 'showEdit.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">
--> <script type="text/javascript"> function editGoodsOK(no){ document.getElementById("no").value=no;
document.getElementById("form").submit(); }
</script> </head> <body>
<form action="goodsServlet" id="form">
<table border="1" cellpadding="0" cellspacing="0" width="500">
<tr>
<td>商品编号</td>
<td>商品名</td>
<td>生产日期</td>
<td>地址</td>
<td>商品类型</td>
<td>操作</td>
</tr> <%
ResultSet rs = (ResultSet)request.getAttribute("rs");
while(rs.next()){
%>
<tr>
<td><input type="text" name="no" value="<%=rs.getString("no") %>" readonly="readonly"/></td>
<td><input type="text" name="name" value="<%=rs.getString("name") %>"/></td>
<td><input type="text" name="time" value="<%=rs.getString("time") %>"/></td>
<td><input type="text" name="address" value="<%=rs.getString("address") %>"/></td>
<td><input type="text" name="type" value="<%=rs.getString("type") %>"/></td>
<td>
<input type="button" value="确认修改" onclick="editGoodsOK('<%=rs.getString("no") %>')"/>
</td>
</tr>
<%
}
%>
<input type="hidden" name="no" id="no"/><br/>
<input type="hidden" name="status" value="editOK"/><br/>
<input type="hidden" name="goodsName" value="<%=request.getParameter("goodsName")%>"/><br/>
<input type="hidden" name="goodsType" value="<%=request.getParameter("goodsType")%>"/><br/>
</table>
</form>
</body>
</html>

4、DBHelper类

package com.cn.tools;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement; /**
* ��ȡ���ݿ���������Ӷ���?
* �ر����ݿ�����ĸ������?
* @author ������
*
*/
public class DBHelper {
private static final String className = "com.mysql.jdbc.Driver";
private static final String url = "jdbc:mysql://localhost:3306/jsp?characterEncoding=utf8&useSSL=true";
private static final String uname = "root";
private static final String upass = "**********"; /**
* ��ȡ���ݿ����Ӷ���ķ���?
*/
public static Connection getConn(){
Connection conn = null;
try{
Class.forName(className);
conn = DriverManager.getConnection(url,uname, upass);
} catch(Exception e){
e.printStackTrace();
} return conn;
} /**
* �ر����ݿ����Ӷ���
*/
public static void closeConn(Connection conn){
try{
if(conn!=null){
conn.close();
}
} catch(Exception e){
e.printStackTrace();
}
} /**
* �ر����ݿ��������?
*/
public static void closeStmt(Statement stmt){
try{
if(stmt!=null){
stmt.close();
}
} catch(Exception e){
e.printStackTrace();
}
} /**
* �ر����ݿ��������?
*/
public static void closePstmt(PreparedStatement pstmt){
try{
if(pstmt!=null){
pstmt.close();
}
} catch(Exception e){
e.printStackTrace();
}
} /**
* �ر����ݿ��������?
*/
public static void closeRs(ResultSet rs){
try{
if(rs!=null){
rs.close();
}
} catch(Exception e){
e.printStackTrace();
}
}
}

5、GoodsServlet

package com.cn.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.cn.tools.DBHelper; public class GoodsServlet extends HttpServlet { private DBHelper db = new DBHelper();
private Connection conn = db.getConn(); public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String status = request.getParameter("status"); if(status.equals("findAll")){
this.findAll(request, response);
}else if(status.equals("delete")){
this.delete(request, response);
}else if(status.equals("edit")){
this.edit(request, response);
}else if(status.equals("editOK")){
this.editOK(request, response);
} } /**
* 查询商品
*/ public void findAll(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String goodsName = request.getParameter("goodsName");
String goodsType = request.getParameter("goodsType"); ResultSet rs = null;
try {
Statement st = conn.createStatement(); String sql = "select * from goods t where 1=1 "; if(goodsName!=null||!goodsName.equals("")){
sql += " and t.name like '%"+goodsName+"%'";
}
if(goodsType!=null||!goodsType.equals("")){
sql += " and t.type like '%"+goodsType+"%'";
} rs = st.executeQuery(sql); } catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} request.setAttribute("rs", rs);
request.getRequestDispatcher("show.jsp").forward(request, response);
} /**
* 删除商品
*/
public void delete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String no = request.getParameter("no");
try {
Statement st = conn.createStatement();
st.execute("delete from goods where no='"+no+"'");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.findAll(request, response);
} /**
* 修改数据展示
*/
public void edit(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String no = request.getParameter("no");
ResultSet rs = null;
try {
Statement st = conn.createStatement();
rs = st.executeQuery("select * from goods where no='"+no+"'");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("rs", rs);
request.getRequestDispatcher("showEdit.jsp").forward(request, response);
} /**
* 确认修改
*/
public void editOK(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String no = request.getParameter("no");
String name = request.getParameter("name");
String time = request.getParameter("time");
String address = request.getParameter("address");
String type = request.getParameter("type"); try {
Statement st = conn.createStatement();
st.execute("update goods set name='"+name+"',time='"+time+"',address='"+address+"',type='"+type+"' where no='"+no+"'");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.findAll(request, response);
} }

jsp查询修改的更多相关文章

  1. python查询修改配置文件功能

    阅读目录 一.python查询功能代码 1.查询修改配置文件 global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 local2 i ...

  2. mysql常用快速查询修改操作

    mysql常用快速查询修改操作 一.查找并修改非innodb引擎为innodb引擎 # 通用操作 mysql> select concat('alter table ',table_schema ...

  3. 第11章—使用对象关系映射持久化数据—SpringBoot+SpringData+Jpa进行查询修改数据库

    SpringBoot+SpringData+Jpa进行查询修改数据库 JPA由EJB 3.0软件专家组开发,作为JSR-220实现的一部分.但它又不限于EJB 3.0,你可以在Web应用.甚至桌面应用 ...

  4. Atitit. 注册表操作查询 修改 api与工具总结 java c# php js python 病毒木马的原理

    Atitit. 注册表操作查询 修改 api与工具总结 java c# php js python 病毒木马的原理 1. reg 工具 这个cli工具接口有,优先使用,jreg的要调用dll了,麻烦的 ...

  5. mysql 数据库 添加查询 修改 删除

    cmd 命令行模式操作数据库 添加查询 修改 删除 ( 表 字段 数据)   一 查看数据库.表.数据字段.数据 1 首先配置环境变量 进入mysql  或者通过一键集成工具 打开mysql命令行   ...

  6. jsp 实现修改和删除功能

    main.jsp   实现查询 在此界面快捷方式到修改界面 点击修改  会把数据传递到exit.jsp 修改   edit.jsp 前面数据: 数据库: /* Navicat Premium Data ...

  7. DataTable ajax分页+删除+查询+修改

    这个框架前前后后跳进了很多次坑,也算是本人比较愚笨吧做了很长的时间而积累的经验... dataTable用了很久,今天在此总结一下使用方法以及常用属性的解释. Html代码 : <div cla ...

  8. eclipse 工程默认编码修改 JSP编码修改

    1. Window->Preferences->General->Workspace->Text file encoding 将其改为UFT-8  新建的文件即为UTF-8编码 ...

  9. 查询修改linux 打开文件句柄数量

    查询系统支持最大可打开文件句柄数量: #vi /proc/sys/fs/file-max 查询当前连接用户最大可打开文件句柄数量: #ulimit -a 修改当前连接用户最大可打开文件句柄数量: #u ...

随机推荐

  1. 【BZOJ1299】巧克力棒(博弈论,线性基)

    [BZOJ1299]巧克力棒(博弈论,线性基) 题面 BZOJ 题解 \(Nim\)博弈的变形形式. 显然,如果我们不考虑拿巧克力棒出来的话,这就是一个裸的\(Nim\)博弈. 但是现在可以加入巧克力 ...

  2. luogu3263/bzoj4002 有意义的字符串 (数学+矩阵快速幂)

    首先我们发现$\frac{b+\sqrt{d}}{2}$这个形式好像一元二次方程的求根公式啊(???反正我发现不了) 然后我们又想到虽然这个东西不好求但是$(\frac{b-\sqrt{d}}{2}) ...

  3. redis健康检查与故障转移

    哨兵三个定时监控任务 每隔10s每隔sentinel节点会向主节点和从节点发送info命令获取最新的拓扑结构 每隔2S,每个sentinel节点会向redis数据节点的__sentiel__:hell ...

  4. 51Nod--1295 XOR key (可持久化tire树)

    题目链接 1295 XOR key 可持久化tire树模版题 数组一定要开够 不然数组不够的话就容易tle 吃了两次亏 #include<bits/stdc++.h> using name ...

  5. SFTP多文件上传,删除

    公司项目中需要把项目的相关文件上传到服务器的tomcat中,需要在项目中进行以下几步操作: 1.添加项目信息,包括名称,描述,服务器ip,sftp的用户名,密码,端口号等,存在配置,部署,删除等操作 ...

  6. Zabbix监控服务器硬盘状态

    安装Iptables服务: [root@localhost /]# yum install iptables-services [root@localhost /]# vim /etc/sysconf ...

  7. MongoDB查询内嵌数组(限定返回符合条件的数组中的数据)(1)

    https://blog.csdn.net/bicheng4769/article/details/79579830 项目背景 最近在项目中使用mongdb来保存压测结果中的监控数据,那么在获取监控数 ...

  8. 在 Docker 中使用 mysql 的一些技巧

    启动到后台:  docker-compose start docker-composer 执行命令: entrypoint: pwd app: build: ./app working_dir: /a ...

  9. nc 使用实例

    nc.exe -h即可看到各参数的使用方法.基本格式:nc [-options] hostname port[s] [ports] ...nc -l -p port [options] [hostna ...

  10. [NOI2018]归程

    今年D1T1,平心而论,如果能想到kruskal重构树还是很简单的. ......苟屁啊!虽然跟其他的比是简单些,但是思维难度中上,代码难度中上,怎么看都很符合NOI T1啊. 本题还有可持久化并查集 ...