0

I have a jsp page which takes a parameter from my Java code and calls the URL onLoad as below.
When I do this the form strips the resultant Url's parameters. As in everything after ? is stripped. So the below result url http://hostname/abc?data=123 appears as http://hostname/abc which is not expected.
What am I missing or is it completely wrong to use form for GET requests. Is there a better way to do this using javascript like window.location=result; My jsp page is:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

</head>

<body onload="javascript:document.Form.submit()">
     <%
     String result = (String)request.getAttribute("result");
     %>
     <form action= <%= result %> method="get" name="Form">

         
     </form>

 </body>
</html>



james2611nov
  • 473
  • 2
  • 10
  • 27

1 Answers1

1

Normaly when a form is submitted the url is constructed by the form and all form controls are passed as query parameters (that happens only when the form has the submit method of GET).

You trying to construct the url with query parameters that the form is supposed to construct is wrong. Hence you get the error.

Share with us what you try to achieve so we can understand a bit better how to help you.

<body onload="javascript:document.Form.submit()">

What I understand from that is that you try when the page is first loaded to call another url. That could happen on servlet level so there you can do with java whatever you want.

Using pure javascript as described here get request from js you could achieve what you try to do with the form action.

However keep in mind that this would not be considered best practice when you deal with JSP

Right. I am trying to redirect to another URL with the right parameter. I have now updated form to have a hidden input parameter named as data as below: My final intended URL is http://hostname/abc?data=a1%2Bz%3D%3D However the value in the form keeps appending the numeric 25 after each % so the value in data is a1%252Bz%253D%253D. Is some wierd URL encoding taking place here.

Right the browser will try to encode each url before trying to access it. Check here browser encoding .As you can see % will be encoded to %25. On the other end when some system parses that url it will first decode it so the %25 will again become 25. That's pretty normal

Panagiotis Bougioukos
  • 15,955
  • 2
  • 30
  • 47
  • Right. I am trying to redirect to another URL with the right parameter. I have now updated form to have a hidden input parameter named as data as below: `
    ` My final intended URL is `http://hostname/abc?data=a1%2Bz%3D%3D` However the value in the form keeps appending the numeric 25 after each % so the value in **data** is `a1%252Bz%253D%253D`. Is some wierd URL encoding taking place here.
    – james2611nov Jan 31 '21 at 05:33
  • Worked out for me with the form as above and URL decoding before sending the request. Thanks. – james2611nov Feb 01 '21 at 00:11