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

11,637

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

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

In your servlet:

String htmlFormName = request.getParameterValue("htmlFormName");
Share:
11,637
Rob Breidecker
Author by

Rob Breidecker

Software consultant and developer. https://twitter.com/robbr https://www.linkedin.com/in/breidecker

Updated on June 29, 2022

Comments

  • Rob Breidecker
    Rob Breidecker almost 2 years

    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.