如何将表单中的新文本值动态传递给jsp

how to pass the new text value in a form to jsp dynamically

本文关键字:动态 jsp 文本 表单 新文本      更新时间:2023-09-26

我有以下代码:

code here: <input type='text' id='2' value='10:00' />

这是一个可编辑的文本框字段,包含预先填充的数据。每当用户输入新值时,我如何在jsp中获得文本框的新值。请帮忙。

试试这个。

<input type='text' id='2' value='10:00' onkeyup="get(this)"/>

在头标签中使用此脚本

<script>
function get(text)
{
var input = text.value;
alert(input);   //displaying the  value
}

</script>

假设您有以下jsp(将名称添加到输入中),假设您将此表单提交到同一个jsp(即someAction.jsp,尽管它应该是servlet或控制器)。

<form action="someAction.jsp">
<input type='text' name='myName' id='2' value='10:00' />
<input type='submit' value="Submit">
</form>

然后单击提交按钮,您可以在jsp/servlet/controller:中获得这个变量myName

    // this will be value of this textbox
    // what user entered (as I understand you would like to know that).
    String someVar = request.getParameter("myName");