问题描述:
<script type="text/javascript">
function toPage(url) {
window.open(url);
}
</script>
<form action="Xxx.action?method=list" method="post">
记录1 <input type="button" onclick="toPage(url);" value="操作">
记录2 <input type="button" onclick="toPage(url);" value="操作">
记录3 <input type="button" onclick="toPage(url);" value="操作">
记录4 <input type="button" onclick="toPage(url);" value="操作">
......
记录N <input type="button" onclick="toPage(url);" value="操作">
</form>
上述代码的 操作 的url中含有大量的参数,如:
/exam/review.action?method=getPaper?stuId=4028810a31b834960131b838qn20090204&stuNo=20095338&paperId=402881ed347812a901347813f96d0001&examId=402881ed347812a90134781601fe0023&classNo=QN200902
由于Get 方式传输的数据量非常小,一般限制在 2 KB 左右,而如此之长的数据很有可能会超过其大小,所以想用post方式提交。
-------------------------------------------------------------------------------------------------------------------------------
解决方法:
<script type="text/javascript">
function toPage(url, data) {
// data 格式如下:
// stuId=4028810a31b834960131b838qn20090204&stuNo=20095338&paperId=402881ed347812a901347813f96d0001&examId=402881ed347812a90134781601fe0023&classNo=QN200902
data += '&'; // 用来分割最后一个参数
var target = '_blank';
var tempForm = document.createElement("form");
tempForm.id = "tempForm1";
tempForm.method = "post";
tempForm.action = url;
tempForm.target = target;
var count = 0;
var t = '';
var name = '';
var value = '';
// 将data分割分割成name和value,并根据其创建隐藏域
for (var i=0; i<data.length; i++) {
var tmp = data.charAt(i);
if(tmp != '=' && tmp != '&') {
t += tmp;
} else {
count++;
if(count % 2 != 0) {
name = t;
t = '';
} else {
value = t;
t = '';
var hideInput = document.createElement("input");
hideInput.type = "hidden";
hideInput.name = name;
hideInput.value = value;
tempForm.appendChild(hideInput);
}
}
}
document.body.appendChild(tempForm);
tempForm.submit();
document.body.removeChild(tempForm);
}
</script>
<form action="Xxx.action?method=list" method="post">
记录1 <input type="button" onclick="toPage(url, data);" value="操作">
记录2 <input type="button" onclick="toPage(url, data);" value="操作">
记录3 <input type="button" onclick="toPage(url, data);" value="操作">
记录4 <input type="button" onclick="toPage(url, data);" value="操作">
......
记录N <input type="button" onclick="toPage(url, data);" value="操作">
</form>
-------------------------------------------------------------------------------------------------------------------------------
总结:
1.get与post的区别:
get传输数据量小,执行效率快,不安全
post传输数据量大,安全
2.js分割字符串
3.js document.createElement()方法
-------------------------------------------------------------------------------------------------------------------------------
参考网址:
http://www.cnblogs.com/jack-liang/archive/2011/07/07/2099921.html
http://www.cnblogs.com/caicainiao/archive/2011/07/02/2096275.html
http://www.cnblogs.com/shenba/archive/2009/08/16/1547429.html
分享到:
相关推荐
这部分代码定义了一个包含数字和字母的字符串`$str`,然后通过`explode`函数将其分割成一个数组`$list`。接下来通过循环随机选取数组中的元素组成长度为5的验证码字符串`$verifyCode`。 ##### 4. 存储验证码到会话...
- `eval()`: 执行字符串中的 JavaScript 代码。 - `isNaN()`: 检查一个值是否为 NaN。 #### 4. 对象使用 - `Date` 对象:获取当前日期和时间。 - `setTimeout()`: 延迟执行函数。 - `clearTimeout()`: 取消延迟执行...
// 分割字符串,得到多个id String[] idArray = ids.split(","); // 执行删除操作 for (String id : idArray) { // 使用JdbcDao的delete方法 jdbcDao.deleteEmployee(Integer.parseInt(id)); } // 返回结果...
在这里,Servlet可能检查数据库中是否存在相同的用户名,然后构建一个包含验证结果和其他信息的字符串,如错误消息、图片链接等,最后以`|`分隔。 - Servlet需要设置字符编码以正确处理中文字符,这里使用`request....
通常我们会使用JavaScript的内置方法`Math.random()`结合一些字符串操作技巧来生成所需的内容。 #### 在JSX中编写条件语句 在实际开发过程中,我们经常需要根据不同的条件来渲染不同的UI。React支持在JSX中使用...
- **toString**:返回 Widget 的字符串表示形式。 - **uninitialize**:取消初始化 Widget。 #### 七、DomWidget DomWidget 是 Widget 的一个子类,它主要负责渲染和管理 Widget 的 DOM 结构。 - **containerNode...