Frage

I have a form with action as loader.jsp.

<form action="loader.jsp?WindowName=abc&compname=xyz" method="POST">
</form>

When I submit this form, Inside the loader.jsp I am able to access the request parameters using

String windowName = <%=request.getParameter("WindowName")%>;

But when I change the form method to GET I am not able to access the parameter using the above statement. It gives null.

When I inspected the request in the Fiddler, URL doesn't even contain the request parameters when the method is GET.

Please help.

War es hilfreich?

Lösung

Because when you set your form method to get, what's in the form is gonna be added as querystring and therefore the querystring inside action attr is being ignored. Try to add your values as hidden fields to your form to get them like:

<form action="loader.jsp" method="GET">
  <input type="hidden" name="WindowName" value="abc">
  <input type="hidden" name="compname" value="xyz">
</form>

BTW this is not a jsp issue. This is the html's form element behaviour.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top