【问题标题】:How to keeping textarea content after a form submition with jsp not duplicate?使用jsp提交表单后如何保持textarea内容不重复?
【发布时间】:2016-08-28 08:38:24
【问题描述】:

我想在提交表单后将 textarea 内容保留在其归档中...我使用 jsp 我尝试这样做 here solve to same problem 但它不适用于我 我的代码:

 <form class="contact-form" id="preview-form"   action="textAreaData"  method="post">
 <textarea id="preview-form-comment" name="preview-form-comment">${fn:escapeXml(param.preview-form-comment)}</textarea>
 <input type="submit" name="preview-form=submit" id="preview-form-submit" value="Submit"  >
 </form>

这是结果: display number 0 and when I submit the input it Disappears from its filed after a form submition

怎么了?可以帮忙吗?

【问题讨论】:

  • @BalusC 可以帮忙吗?

标签: jquery html forms jsp


【解决方案1】:

好的,简单的方法:

在你的 servlet 中定义:

String comment = request.getParameter("preview-form-comment") ;

request.setAttribute("anydata", comment);

在你的文本区域写:

 <textarea id="preview-form-comment" name="preview-form-comment">${anydata}</textarea>

它运行 :) 祝你好运

【讨论】:

    【解决方案2】:

    一种方法是使用 php。我将在下面发布一个示例:

    <input type="text" placeholder="Your name" name="name" value="<?php if(isset($_POST['name'])){echo $_POST['name'];}?>">
    

    我不确定你是否了解 php,但基本上这里是细分。从您的 html 看来,您正在自我提交意味着返回同一页面。因此,当您将数据发布到页面时,我们可以使用 $_POST['name of the field']

    访问它

    也就是说,我们可以使用 isset php 方法来查看表单是否已发布数据以及是否已使用旧值填充该字段。

    【讨论】:

    • 他使用 jsp 而不是 php @Tim Hinz
    • 我的错,你可以使用:String token = request.getParameter("token");改为jsp中的方法
    • 和jsp中的isset等价物是这样的:变量名未定义
    猜你喜欢
    • 1970-01-01
    • 2018-07-05
    • 2012-08-25
    • 1970-01-01
    • 2018-12-26
    • 2015-04-23
    • 2010-10-21
    相关资源
    最近更新 更多