博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jsp实现表格的增删功能
阅读量:7218 次
发布时间:2019-06-29

本文共 1934 字,大约阅读时间需要 6 分钟。

<%@ page import="java.util.List" %>

<%@ page import="bean.Hero" %>
<%@ page import="java.util.ArrayList" %>

<%

response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
String xh=request.getParameter("xh");
String xm=request.getParameter("xm");
String ch=request.getParameter("ch");
List<Hero> list=new ArrayList<Hero>();

%>

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

<html>
<head>
<title>hero</title>
</head>
<body>
<%

Hero h1=new Hero();h1.setCh("及时雨");h1.setXm("宋江");h1.setXh("1");Hero h2=new Hero();h2.setCh("黑旋风");h2.setXm("李逵");h2.setXh("2");list.add(h1);list.add(h2);

%>

<script>

//增加功能function  addHero() {    <%         Hero h=new Hero();         h.setXh(xh);         h.setXm(xm);         h.setCh(ch);        boolean flag=true;         for(Hero he:list){             if(he.getXh().equals(xh)){                 flag=false;                 %>alert("该用户已存在,请勿重复添加")<%                 break;             }         }         if (flag==true){             list.add(h);             }    %>}    //删除功能function deletHero(elm) {    elm.parentElement.parentElement.remove();}

</script>

序号 姓名 绰号 操作

<%

for(Hero hero:list){
//如果为空,就不添加
if(hero.getCh()==null){
break;
}
%><tr>
<td><%=hero.getXh()%></td>
<td><%=hero.getXm()%></td>
<td><%=hero.getCh()%></td>
<td><span οnclick="changeHero(this)" style="cursor: pointer;">修改</span></td>
<td><span οnclick="deletHero(this)" style="cursor: pointer;">删除</span></td>
</tr>
<% }%>

 

<form action="" method="post" name="form1">

序号:<input type="text" name="xh" id="xh"><br>
姓名:<input type="text" name="xm" id="xm"><br>
绰号:<input type="text" name="ch" id="ch">
<h1><button type="submit" οnclick="addHero()">添加</button>
<button type="" οnclick="changeHero()">修改</button></h1>
</form>
<%

%>

</body>

</html>

转载于:https://blog.51cto.com/13670525/2150086

你可能感兴趣的文章
jetty404web界面服务器信息隐藏
查看>>
22个Photoshop网页设计教程网站推荐
查看>>
如何让程序员更容易的开发Web界面?重构SmartAdmin展示TinyUI
查看>>
centos7 python2和python3共存
查看>>
rhel6.2配置在线yum源
查看>>
分级聚类算法
查看>>
Web Services 入门(之二)
查看>>
随机模拟MCMC和Gibbs Sampling
查看>>
网络安全是一种态度
查看>>
POJ1131 Octal Fractions
查看>>
mysql-ulogd2.sql
查看>>
119. Pascal's Triangle II - Easy
查看>>
349. Intersection of Two Arrays - Easy
查看>>
[算法练习]最长公共子串(LCS)
查看>>
p转c++
查看>>
树(tree)
查看>>
codevs——2645 Spore
查看>>
ssh服务之 远程登录和端口转发
查看>>
java环境配置正确,但是tomcat不能启动的解决办法
查看>>
我就是想找个人聊聊天,说说我这近四年来的经历
查看>>