Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...