Link to home
Start Free TrialLog in
Avatar of kumare
kumareFlag for United States of America

asked on

Append key/value pair in URL java

We have a scenario in our mobile app where we want to add a parameter to the header or url so that the firewall can validate the request based on the parameter sent. Authentication needs to be done before it reaches the server. Is there anyway to append any information to url or request headers for the subsequent requests from the server.

 I like  to append name/value pairs to the URL's from within a servlet or action class so that based on the key value pair we can have a rule in firewall to validate the request.

Avatar of for_yan
for_yan
Flag of United States of America image

If I understand you correctly then if you use attribute method=get
in the <form... > element then it will pass your parameters in
the URL itself
Yu can then use say hidden element(s)  to pass any parameters you want in the URL
string to the next page
Avatar of kumare

ASKER

all the jsp's use POST method.
You can use servlet instead of JSP
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kumare

ASKER

this is an existing application so I would not be able to change the architecture.
So what can you do?
Maybe you can change the action of the form direct it to intermediate servlet
which would modify the URL and then call your ultimate page
and in that itntermediate servlet uyou'll change as you want.
Avatar of kumare

ASKER

moreover GET would have size limit, the app might have many fields in the form.
Avatar of Dave Baldwin
Last I heard, Authentication is always done by the server.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kumare

ASKER

This is not a complete solution, as we are not looking for GET requests.
I guess you don't understand then that "I like  to append name/value pairs to the URL's" is by definition a GET request.  You can not put or see POST requests in the URL.
Avatar of kumare

ASKER

Dave .. you can append parameters to POST requests explicitly like this

<form id="form1" name="form1" method="post" action="print?<%= session.getAttribute("auth") %>

let me know if this is wrong
No, that is not 'wrong' but the server receives the part after the URL and '?' as a query string and puts that in the GET array, not the POST array.  I have done exactly what you are talking about a number of times and you will Not find that info the POST array on the server.  It will be in the GET array though sometimes (in PHP), you can retrieve it thru the REQUEST array which in PHP combines both POST and GET.

So when you submit a form as a POST with a query string, you are submitting both POST and GET information.  Yes, you can do that (I have done that) but you have to know which is which so you know where to look for the different items in the program page that receives the info.

Note that these things are independent of the language, they are part of the HTTP protocols that browsers and servers use.  http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol