是否可以从 Java HTTPServletRequest 中检索表单名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1252125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 15:49:33  来源:igfitidea点击:

Is it possible to retrieve the form name from a Java HTTPServletRequest?

javahttpformsservlets

提问by Rob Breidecker

I would like to get the name of the form used to post parameters from a Java HTTPServletRequest object. Is this possible. I don't see any method that looks like it will return it to me.

我想获取用于从 Java HTTPServletRequest 对象发布参数的表单的名称。这可能吗。我没有看到任何看起来会返回给我的方法。

回答by ChssPly76

HTML form name is NOT submitted as part of the request. If you need it (why?) you can submit it as hidden input instead:

HTML 表单名称不作为请求的一部分提交。如果您需要它(为什么?),您可以将其作为隐藏输入提交:

<form name="myForm" action="/my_servlet">
  <input type="hidden" name="htmlFormName" value="myForm"/>
  ...

In your servlet:

在您的 servlet 中:

String htmlFormName = request.getParameterValue("htmlFormName");