js获得jsp页面表单数据

JavaScript011

js获得jsp页面表单数据,第1张

你以上的代码不是html ,真正的html 是服务器返回浏览器的代码。上面只是一个servlet原码,要明白servlet 与html 的区别是什么。

以下是方法:

<!-- 方法1 纯html 表单提交-->

<form action="/actionpath.do">

<input type="text" name="pro1">

<input type="text" name="pro2">

<input type="submit" value="提交">

</form>

<!-- 方法2 用js提交-->

<form id="frm" action="/actionpath.do">

<input type="text" name="pro1">

<input type="text" name="pro2">

<input type="button" value="提交" onclick="return check()">

</form>

<script type="text/javascript">

function check(){

document.getElementById("frm")

form.submit()

}

</script>

详细请参考:http://www.360cat.cn/it/note/java_john2/info/0-280_0_0.html

直接在td里面添加click事件click="test(this)",然后就可以比较容易的获取到table各行各列的值

this.value就是里面的值,还有this.innerText,this.HTMl具体用什么,根据情况考虑

jsp在页面上获取java参数总共有以下方法:

(1)直接在URL请求后添加

如:<a href="thexuan.jsp?action=transparams&detail=directe")直接传递参数, 特别的在使用response.sendRedirect做页面转向的时候,也可以用如下代码: response.sendRedirect("thexuan.jsp?action=transparams&detail=directe") ,可用request.getParameter(name)取得参数

(2)jsp:param

它可以实现主页面向包含页面传递参数,如下:

<jsp:include page="Relative URL">

<jsp:param name="param name" value="paramvalue" />

</jsp:include>

还可以实现在使用jsp:forward动作做页面跳转时传递参数,如下:

<jsp:forward page="Relative URL">

<jsp:param name="paramname" value="paramvalue" />

</jsp:forward>通过这种方式和一般的表单参数一样的,也可以通过request.getParameter(name)取得参数

(3)设置session和request

通过显示的把参数放置到session和request中,以达到传递参数的目的

session.setAttribute(name,value)

request.setAttribute(name,value)

取参数:value=(value className)session.getAttribute(name)

value=(value className)request.getAttribute(name)