当前位置:编程学习 > JAVA >>

jsp中,点击链接时如何把Input框的值传过去?



有一个List列表,里有的‘姓名,原手机号’等字段,‘新手机号’为客户输入的值。

如上图,点击链接时,需要把“姓名”和“新手机号”的值传过去,然后在相应的Java 类里取出来。怎么取? --------------------编程问答-------------------- 图呢? --------------------编程问答-------------------- 如果是链接,需要通过js让form表单提交,如果是submit可以直接提交

后台获取

request.getParameter("name")  
request.getParameter("tel")   --------------------编程问答-------------------- 可以像2楼说的一样,也可以直接拼成对应的URL然后跳转 --------------------编程问答--------------------

<c:if test="${! empty mobileList}">
         <br>
         <table class="list_table" border="1" cellspacing="0" cellpadding="0" id="list">
           <tr>
           <th bgcolor="e6e6e6" align="center" width="30%" height="30">姓名</th>
             <th bgcolor="e6e6e6" align="center" width="30%" height="30">原手机号</th>
                <th bgcolor="e6e6e6" align="center" width="40%" height="30">新手机号</th>
             <th bgcolor="e6e6e6" align="center" width="40%" height="30"> </th>
           </tr>          
           <c:forEach items="${mobileList}" var="row" varStatus="status">
             <tr>
               <td nowrap><c:out value="${row.recipientsName}" /></td>
               <td nowrap><c:out value="${row.recipientsMobile}" /></td>
               <td nowrap><input name="newReciMobile" size="15" maxlength="12" type="text" value="<c:out value="${newReciMobile}"/>" /></td>
               <td nowrap><a href="javascript:checkForm('<c:out value="${row.recipientsName}"/>', '<c:out value="${newReciMobile}"/>')">修  改</a></td>
               </tr>
               </c:forEach>
               </table>   
              </c:if>          

<script language="javascript">
 function checkForm(recipientsName, newReciMobile){
 alert("newReciMobile="+newReciMobile);
 if(document.form1.newReciMobile.value == ""){
 alert("请输入新手机号!");
 return false;
 }
document.form1.action="UpdateReciMobileResult.do?recipientsName="+recipientsName+"&newReciMobile="+newReciMobile;
document.form1.submit();
 //window.href="UpdateReciMobileResult.do?recipientsName="+recipientsName+"&newReciMobile="+newReciMobile;
 return true;
 }
</script>


目前的代码如上所示。
存在的问题:
1、在Java类里取出newReciMobile时,发现是个数组,数据第一个值是空串,第二个值是页面输入的值。
2、Js里“alert("newReciMobile="+newReciMobile);”这句话输出的是个空串。

问:如何修改才能在Java类里正确取是newReciMobile的值? --------------------编程问答--------------------
引用 1 楼 todaydiy 的回复:
图呢?


你们看不到图吗? --------------------编程问答-------------------- 完全看不到 --------------------编程问答-------------------- [img=http://hi.csdn.net/space-2431129-do-album-picid-953242.html][/img]

再贴一次图试试。
能看到了吗?
还有,代码能看到吗? --------------------编程问答--------------------

再贴一次…… --------------------编程问答-------------------- 楼主的问题是:
1. 你在这里javascript:checkForm('<c:out value="${row.recipientsName}"/>', '<c:out value="${newReciMobile}"/>')

已经定死了checkForm(recipientsName, newReciMobile)这里面的newReciMobile值为<c:out value="${newReciMobile}"/>,而这个<c:out value="${newReciMobile}"/>是空,
所以你的Js里“alert("newReciMobile="+newReciMobile);”这句话输出的是个空串。

2. 在Java类里取出newReciMobile时,发现是个数组,数据第一个值是空串,第二个值是页面输入的值。

这里的原因是 你本身传入的值是<c:out value="${newReciMobile}" />为一个空串,而当你填入值后
<input name="newReciMobile" size="15" maxlength="12" type="text" value="<c:out value="${newReciMobile}" />被你用了document.form1.submit();这样的提交方式,就把input实际输入的值提交过去了。。。所以是数组。。

解决方法:
1. 你的提交有问题:
document.form1.action="UpdateReciMobileResult.do?recipientsName="+recipientsName+"&newReciMobile="+newReciMobile;
document.form1.submit();
这种提交方式有严重的问题,,要么就用location.href= "UpdateReciMobileResult.do?recipientsName="+recipientsName+"&newReciMobile="+newReciMobile;这种js带参的提交方式。
要么就用document.form1.submit();直接提交表单的方式。。。而你上面的方式是两种方式都用上了,所以提交过去是数组。。
2. 
javascript:checkForm('<c:out value="${row.recipientsName}"/>', '<c:out value="${newReciMobile}"/>')
这里面的参数不要用读取出来的参数写死了。。这里的参数换成两个input中的值。。即你输入input的值。。
--------------------编程问答-------------------- 建议
如果作修改的话
最好不要在一览里面做 --------------------编程问答-------------------- 同意9楼. --------------------编程问答-------------------- 这个表对应的应该要有个ID吧?通过ID直接去数据库查出来姓名。看你的手机号好像是在页面上输入的,可以用request.getParameter("新手机号文本框的name")   
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,