【问题标题】:using the POST variables in jsp [duplicate]在jsp中使用POST变量[重复]
【发布时间】:2016-02-04 16:44:48
【问题描述】:

我在我的网站上有一个表格,随邮件一起发送。我必须在同一页面中使用变量而不重新加载数据。我有这个。

     <html>
     <head>
      <meta http-equiv="Content-Type" content="text/html"; charset="ISO-8859-1">
       <title>Ejemplo de carga de datos</title>
       <script src="/Scripts/jquery-1.9.1.js"></script> 

     <script>
  $(function(){ 
     $("#form").submit(function(event){

    var str = $(this).serialize();
    alert(str);



       <% System.out.println(request.getParameter("radioValue00")); %> 
   });
 });
</script>
</head>
 <body>
<h3>Ejemplo de captura de datos</h3>

 <form name="form" id="form"  method="post" enctype="multipart/form-data" >


  Choose one:

  <input type="radio" name="radioValue00" id ="radioValue00S" value="S" required> Yes
   <input type="radio" name="radioValue00" id ="radioValue00N" value="N"> No

    <input type="submit" name="submit" value="Enviar datos" />

     </form>

</body>
</html>



        <% System.out.println(request.getParameter("radioValue00")); %> 
    });
});
</script>

当我alert(str) 时,我看到以下内容:

我可以看到所有的数据,所以已经发送了,但是尝试打印时却是空的,我该如何使用呢?

【问题讨论】:

  • 你能说明你在哪里使用 POST 吗?
  • 您正在将值打印到 JS script 块的中间。提交表单后,您只会在屏幕上看到一个 JS 错误。您是否检查了源以查看是否存在值?
  • 我看到当我执行 alert(str) 时该值存在,并且它有“S”,但是当尝试使用 jsp 打印时它会打印“null”

标签: jquery forms jsp


【解决方案1】:

将 enctype="multipart/form-data" 替换为 enctype="application/x-www-form-urlencoded" (或者完全删除 enctype,因为 enctype="application/x-www-form-urlencoded" 是无论如何默认)

请注意 enctype="multipart/form-data" 仅在上传文件(和二进制 dana)时有用,但不幸的是 request.getParameter 总是返回 null (当然,这种情况存在解决方法)

【讨论】:

  • 谢谢!但这不是我的问题。如果我重新加载网站我可以获得数据,我的问题是如何在不重新加载的情况下使用
猜你喜欢
  • 2015-11-17
  • 2012-06-20
  • 1970-01-01
  • 2011-05-15
  • 2014-05-20
  • 2012-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多