jsp 获取div里面的form的action

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jsp 获取div里面的form的action相关的知识,希望对你有一定的参考价值。

代码如下:
<div id="head">
<form name="login">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username" class="text"/></td>
</tr>
<tr>
<td>密 码:</td>
<td>
<input type="password" name="password" class="password"/>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="button" class="button" value="注册">
<input type="submit" class="button" value="登录">
</td>
</tr>
</table>
</form>
</div>
然后我在struts.xml里面这样设置
<struts>
<package name="struts" extends="struts-default">
<action name="login" class="com.qzj.Action.UserAction">
<result name="success">/LoginResult.jsp</result>
</action>
</package>
</struts>
配置是没问题的,我现在不知道怎么获取div里面的form 的action,我重新试了一个form(没有div的)成功了,但是有div就不行了,不知道怎么解决,希望高手帮忙。

如果 多个 div 就给他一个id 如果只有一个div 就 form 一个 name 就 可以了

若是找不到 再 来个 id就没问题了
参考技术A 直接给form加个id或者哪么属性... 参考技术B 直接给form加一个id,name属性,不管你加多少个div,可以直接拿到form表单对象

html中如何获取表单的数据?

代码如下:
<form id="form1" name="form1" method="post" action="index.php
src=325&item=iframe&action=save&t=&lc=2" onsubmit="return check();" style="width:433px;height:301px">
<table width="433" height="301" cellpadding="0" cellspacing="0" style="background-image:url(images/sub_mi_expo_05.jpg); width:433px; height:301px;">
<tr>
<td height="70"></td>
</tr>
<tr>
<td width="105" align="right" height="40" class="font_color">您的姓名:</td>
<td align="left" width="102" style="width:102px; overflow:hidden;"><input type="text" id="name" name="name1" maxlength="8"/></td>
<td align="right" width="50" class="font_color" style="width:50px; overflow:hidden;">手机:</td>
<td align="left" width="176"><input type="text" id="phone" name="phone1" maxlength="11"/></td>
</tr>
<tr>
<td width="105" align="right" height="45" class="font_color">收票地址:</td>
<td colspan="3"><input type="text" id="address" name="address" maxlength="100" /></td>
</tr>
<tr>
<td width="105" align="right" height="35" class="font_color">快递时间:</td>
<td colspan="3"><input type="radio" name="express" value="3" checked="checked"/>任何一天 <input type="radio" name="express" value="1"/>工作日 <input type="radio" name="express" value="2"/>双休日 </td>
</tr>
<tr>
<td height="55"></td>
<td colspan="3"><p style="width:154px; text-align:center; float:left; height:37px; font-size:12px; color:#FF6666; overflow:hidden; line-height:34px; background-image:url(images/new_cdbm_12.jpg); background-repeat:no-repeat;">已有<font style="font-size:22px; color:#FF0000; font-family:Arial;"></font>人报名</p>
<p style="width:127px; height:37px;float:left;"><input type="submit" value="" id="order_sh" style=" cursor:pointer;background-image:url(images/TIJ_EXPO_NEW_06.jpg); border:0;width:127px; height:37px;" /></p></td>
</tr>
</table>
麻烦大神能写代码的写一下代码!谢谢。

html中获取表单数据的的方法一般有两种,一个是使用form表单的action属性将表单的数据提交给后台,另外一种就是使用JavaScript方法获取表单的数据,然后通过ajax传送给后台。

工具原料:编辑器、浏览器

一、使用表单的方法提交数据

1、利用form表单的action属性来获取表单的数据并提交,代码如下:

<form action="form_action.php" method="get">
  <p>First name: <input type="text" name="fname" /></p>
  <p>Last name: <input type="text" name="lname" /></p>
  <input type="submit" value="Submit" />
</form>

2、以上代码中method指定提交数据的方法为get,action的值是表单数据提交的地址。

二、使用JavaScript方法来获取表单的数据的方法

1、可以使用JavaScript的选择器选择表单的元素并获取其输入的数据,代码如下:

<form action="form_action.php" method="get">
   <p>First name: <input id="bt1" type="text" name="fname" /></p>
   <p>Last name: <input id="bt2" type="text" name="lname" /></p>
   <input type="submit" value="Submit" />
  </form>
   <script>
   console.log($(\'#bt1\').val())
   console.log($(\'#bt2\').val());
   </script>

2、其中$(\'#bt1\').val()就是获取input输入内容的值

参考技术A

document.getElementById('b').value
或者
form1.a.value

在页面间传递,<script>function goURL(theform)  var gourl = "456.html"; 

gourl +="?p="+theform.username.value+"|"+theform.email.value; theform.action = gourl; return true;

</script><form method=get onsubnit="return goURL(this);

"><input type=text name=username><input type=text name=email><input type=button value=提交 

onclick="goURL(this.form)"></form> 在456.html页面用脚本叫URL问号后面的值分割后,再用"|"分割就得到username和email<script>function init()   var url= document.location.href.split("?") 

temp =url.split("|");  

alert("UserName="+temp[0]+"\\n"+"Email="+temp[1]); </script><body onload=init()> </body>

参考技术B java中可以在后台通过request.getParameter(name);来获得;
如:<input type="text" id="name" name="name1" maxlength="8"/>
后台则根据input标签中name的名字来获得:
String name=request.getParameter("name1");
对于php原理也差不多,request中应该有对应方法去获得。
参考技术C $name = $_POST["name1"] ;

就可以取到数据了。
这个代码可以运行下去吗?你的路径存在问题,传的数据可能到不了你要的运行文件。追问

只需获取 您的姓名:手机:收票地址:就可以了值存在文本里

本回答被提问者采纳
参考技术D form标签要回来啊,它们是成对的标签呢

以上是关于jsp 获取div里面的form的action的主要内容,如果未能解决你的问题,请参考以下文章

jsp 多条件查询。

如何通过submit提交form表单获取后台传来的返回值

jsp中如何获取session的值 (第三方获取session的值)

怎么在jsp页面的form表单中加入富文本编辑器???并传递数据到后台进行保存

jsp table的局部刷新

java 在jsp中怎样获取servlet中的数据