使用onclick事件将两个参数提交到同一个servlet中
Using onclick event to submit 2 parameters into a the same servlet
我正试图使用一个提交按钮,使用jsp将两个参数userId
和friendId
传递到同一个servlet中。我能够获得friendId
,但是,我不能获得userId
。
function anotherPageServlet(servletName) {
document.forms[0].method = "post";
document.forms[0].action = servletName;
document.forms[0].submit();
}
function anotherPageServlet1(servletName) {
document.forms[0].method = "post";
document.forms[0].action = servletName;
document.forms[0].submit();
}
<input style="color:#3333ff"
type="submit"
class="rsubmit"
value="<%= retrieving.getDisplayname()%> :"
onclick="anotherPageServlet('ViewingFriendServlet?stringParameter=<%= session.getAttribute("userId") %>'),
anotherPageServlet1('ViewingFriendServlet?stringParameter=<%=retrieving.getoID() %>')"
>
您可能只需要转义引号:
onclick="anotherPageServlet('ViewingFriendServlet?stringParameter=<%= session.getAttribute('"userId'") %>'),
anotherPageServlet1('ViewingFriendServlet?stringParameter=<%=retrieving.getoID() %>')"
我不习惯JSP,但在JSF中,您宁愿将值分配给请求范围的bean,然后调用与该bean一起工作的函数,而不是直接传递这些参数。
编辑:
首先定义onclick函数,然后只调用简单引用。
function servletFoo() {
anotherPageServlet('ViewingFriendServlet?stringParameter=<%= session.getAttribute("userId") %>');
anotherPageServlet1('ViewingFriendServlet?stringParameter=<%=retrieving.getoID() %>');
}
然后在您的HTML:中
<input ... onclick="servletFoo()" />
相关文章:
- jqGrid - 将表单数据提交到 jqGrid,并让 jqGrid 使用这些参数获取数据
- 我可以从 Rails 4 中的按钮提交传递参数吗?
- 我可以使用URL路径提交参数吗
- 使用提交按钮参数自动提交表单
- 提交前筛选表单参数
- 提交输入类型=“;图像“;到另一个servlet时,未能返回任何参数
- bookmarklet在url中添加一个参数并重新提交
- 在提交时更改HTML Post参数
- 在表单提交时使用 URL 发送路由参数
- 日期选取器问题,尝试提交除日期值之外的其他参数
- Struts1 处理程序参数在从引导对话框提交时未传递
- Jqgrid 在第二次获取调用后在查询字符串中提交错误的参数
- Spring提交具有双参数
- 表单提交将取消URL查询字符串中的一个参数
- 在提交表单时停止添加URL参数
- PHP/MySQL-数据库数据的复选框,提交2个参数
- 通过Javascript提交带有参数的表单
- 参数没有从带有javascript的提交表单中获取
- 当使用HTTP GET从数据库中获取数据时,不能在URL中提交参数
- JS-提交参数's值与“&&”;