博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一个form中对应多个动作
阅读量:7079 次
发布时间:2019-06-28

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

如果想要给一个form表单赋予多种操作。如:

在这个表单中,希望可以有“删除”和“移动”两种动作。但是一个form只有一个action处理

要怎样才能用一个action应对两种不同的操作呢?

在servlet的参数HttpServletRequest req中,有一个函数,名为getParameterNames()。

这个参数的含义是:

Returns an
Enumeration of
String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty
Enumeration.
Returns:
an
Enumeration of
String objects, each
String containing the name of a request parameter; or an empty
Enumeration if the request has no parameters

也就是说它可以返回request对象里面的所有参数的名字。

这样一来,我们可以通过赋予不同的按钮以不同的名字来区分我们点击的是哪个操作。

如:

在servlet中打印输出getParameterNames()函数返回的数组,可以看到:

当我们点击“删除”按钮时,输出的内容是:

当我们点击“移动”按钮时,输出的内容是:

也就是说各个操作只会出现一个,因此只要进行逻辑判断就可以知道选择的那些checkbox是希望进行什么操作的了。

转载地址:http://ondml.baihongyu.com/

你可能感兴趣的文章
linux日志(常用命令)
查看>>
history
查看>>
Leetcode: Arranging Coins
查看>>
HttpUtil 【判断网络连接的封装类】
查看>>
【转】TCP分段与IP分片
查看>>
iOS 多线程 NSOperation、NSOperationQueue
查看>>
delphi执行查询语句时的进度条怎么做
查看>>
CF 335A(Banana-贪心-priority_queue是大根堆)
查看>>
python的memcache使用如果对key设置了一个int型
查看>>
Leetcode: Longest Substring with At Most Two Distinct Characters
查看>>
173. Binary Search Tree Iterator
查看>>
[python基础知识]python内置函数map/reduce/filter
查看>>
基因家族收缩和扩张分析 & Selective loss pathway & 泛基因组
查看>>
HDU2089 ------不要62(数位dp)
查看>>
hdu4756 Install Air Conditioning(MST + 树形DP)
查看>>
windows7安装redis过程
查看>>
css 多行文本溢出省略号显示
查看>>
每日源码分析 - lodash(slice.js)
查看>>
antd的sider与router4结合, 后退刷新,菜单高亮
查看>>
用canvas+png实现动图,告别gif
查看>>