当前位置:网站首页>Submit values of various inputs of the form
Submit values of various inputs of the form
2022-06-22 08:00:00 【xiaoke815】
1. When getting parameters on the server ,HttpServletRequest.getParameter(String name) The return result of the method is distinguished according to the following conditions :
1.1 The request message does not contain this parameter , return null.
1.2 The request message contains this parameter , But it's not worth it . for example param1=¶m2=123 Medium param1. In this case, an empty string is returned ””.
1.3 The request message contains multiple parameters with the same name . for example param1=1¶m1=2 Medium param1. In this case , Returns the value of the first parameter . For example, above 1. If you use HttpServletRequest.getParameterValues(String name), Returns a containing all values with the same name Sring Array .
2. <input type="submit" name=" " value=" ">.
There can be more than one... In a page submit Elements , Click on a submit Button time , The browser will form The data is sealed and forwarded to the server , This includes a pair of currently clicked submit Data of information , Click... For the current submit Button on the name and value. Other non clickable submit Button does not pass name and value value .
So you can judge which one is clicked by the following statement submit Button .
if(req.getParameter("submit Button on the name attribute ") != null && req.getParameter("submit Button on the name attribute ").equals("submit Button on the value attribute "))
{
Execute statement
}
If a submit The button doesn't have name attribute . When you click this button , The browser will also form The data is sealed and forwarded to the server , But it doesn't include submit Button itself name and value Information . Therefore, the server cannot judge which button is clicked .
3. <input type="button" name=" " value=" ">
Click on a submit Button time , The browser will automatically submit data to the server , But click on one Button When , The browser simply executes this Button Of onclick event . without onclick event , Just do nothing . Can be in onclick Pass in the event JavaScript Code submission form .
for example :
function button1_click()
{
document.form1.action = “check.jsp”;
document.form1.submit();
}
Click on button Button does not pass button Of name and value value .
4. Various input The transfer name and value The situation of :
Premise is , As long as there is no name attribute , No transmission .
text and textarea Whether it's empty or not , Will be passed to the server , Passed when null value The value is an empty string .
checkbox and radio The situation is , Only the selected one will be passed , What is not selected is not transmitted . If no... Is selected value Of checkbox and radio, Delivered value The value is defaults to ”on”.
hidden No matter how , Will be passed to the server .
5. A practice
5.1 jsp page
<form action="<%=request.getContextPath()%>/checkboxtest"
method="post" target="_blank">
<table>
<tr>
<td>
<input type="checkbox" name="selectbooks" value="1">
</td>
<td>
1
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="selectbooks" value="2">
</td>
<td>
2
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="selectbooks" value="3">
</td>
<td>
3
</td>
</tr>
<tr>
<td>
<input type="submit" name="check" value=" see ">
</td>
<td>
<input type="submit" name="delete" value=" Delete ">
</td>
</tr>
</table>
</form>
5.2 backstage Servlet Code :
resp.setContentType("text/html;charset=UTF-8");
String[] selectBooks = req.getParameterValues("selectbooks");
StringBuffer selectBookIds = new StringBuffer();
int flag = 0;
for (String selectbook : selectBooks) {
if (flag == 0) {
selectBookIds.append(selectbook);
}
else
{
selectBookIds.append("," + selectbook);
}
flag = 1;
}
if(req.getParameter("check") != null)
{
resp.getWriter().println(" Of the selected books id Yes :" + selectBookIds.toString());
}
else if(req.getParameter("delete") != null)
{
resp.getWriter().println(" Deleted books id Yes :" + selectBookIds.toString());
}
else
{
resp.getWriter().println(" Of the returned books id Yes :" + selectBookIds.toString());
}
边栏推荐
- LR 2022 ultra detailed installation tutorial "latest"
- 【图论常见模板题】4种最短路解法和2种最小生成树解法
- [common template problems in graph theory] four shortest path solutions and two minimum spanning tree solutions
- [Oracle database] wet nurse tutorial day15 DDL, DML, index, view, sequence and deadlock are enough
- Energy and interference of waves
- Relative positioning, absolute positioning, fixed positioning
- How can MySQL query the records with the largest consumption amount of each user?
- KVO summary
- Problems caused by canvas palette width and height and canvas width and height
- MySQL intercepts the string cs0000_ 1 medium_ Following characters
猜你喜欢

How can MySQL query the records with the largest consumption amount of each user?

(7) Bidirectional linked list

【宋红康 MySQL数据库 】【高级篇】【06】MySQL的逻辑架构

Win openfeign from simple to deep
![[Oracle database] mammy tutorial day13 date function](/img/ca/90aaa682ec393b1531060377276ca6.png)
[Oracle database] mammy tutorial day13 date function

Remote Desktop Manager

模電實驗——實驗二 JFET共源極放大電路

(7)双向链表

It operation and maintenance knowledge map

Microsoft Remote Desktop 10.7.6 official
随机推荐
(7)双向链表
Unity AssetBundle load
SVN 提交子文件夹问题
(9)顺序队列与栈队列
Microsoft Remote Desktop 10.7.6正式版
[Oracle database] mammy tutorial day13 date function
UI draw line
Stored procedures and functions of MySQL
MySQL index
Canvastotempfilepath of wechat
Realization of readable and writable files in library management system with C language bidirectional linked list
How can MySQL query the records with the largest consumption amount of each user?
LVS Technology Practice
Permission Operation of MySQL
LR 2022 ultra detailed installation tutorial "latest"
Common array operations in JS
先锋期货安全么?期货开户都是哪些流程?期货手续费怎么降低?
Use js to download the current image
【Oracle 数据库】奶妈式教程day15 DDL、DML、索引、视图、序列、死锁这一篇就够了
Relative positioning, absolute positioning, fixed positioning