如何在JSP文件中提交HTML表单的值并将其发送到Servlet?

编程入门 行业动态 更新时间:2024-10-28 16:23:11
本文介绍了如何在JSP文件中提交HTML表单的值并将其发送到Servlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Java的HTTP Servlet中,我想提交一个表单.推荐的方法是什么 输入字段中的值的方式?是否使用隐藏字段 并通过request.getParameter(...)或与request.getAttribute(...)取得它们?

In HTTP servlets for Java I want to submit a form. What is the recommended way of carrying the values from the input fields? Is it using hidden fields and get them through request.getParameter(...) or with request.getAttribute(...)?

推荐答案

所有表单数据都将作为请求参数发送,其中输入字段名称作为参数名称,输入字段值作为参数值.

All the form data will be sent as request parameters with the input field name as parameter name and the input field value as parameter value.

例如

<form action="servletURL" method="post"> <input type="text" name="foo" /> <input type="text" name="bar" /> <input type="submit" /> </form>

具有内部doPost()方法:

String foo = request.getParameter("foo"); String bar = request.getParameter("bar"); // ...

除非您希望传递最终用户不需要输入自己的其他数据,否则无需使用JavaScript将它们传输到其他隐藏字段或无关紧要的内容.

You don't need to use JavaScript to transfer them to other hidden fields or something nonsensicial, unless you want to pass additional data which the enduser don't need to enter itself.

请求属性将反过来使用;用于将结果从servlet传递到JSP文件,然后依次将其显示在所有HTML中.

The request attributes are to be used for the other way round; for passing the results from the servlet to the JSP file which should in turn present them along all the HTML.

  • 我们的servlet Wiki页面-包含Hello World
  • Servlet如何工作?实例化,会话,共享变量和多线程
  • Servlet中的doGet和doPost
  • Our servlets wiki page - contains a Hello World
  • How do servlets work? Instantiation, sessions, shared variables and multithreading
  • doGet and doPost in Servlets

更多推荐

如何在JSP文件中提交HTML表单的值并将其发送到Servlet?

本文发布于:2023-07-13 22:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1102478.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   表单   文件   如何在   并将其

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!