Hiya,
I dont know whether you got the answer or not. But i faced the same problem and was trying many things to make it work.
I succeeded in doing it. Dont know whether it is the RIGHT way, but i can share it anyway
I had to read the raw request so as to maintain the sequence of parameters. I wanted the same sequence in which browser sends to
JBoss instead of HashMap generated order (which is basically the hash order)
I wrote following code and resolved my problem (after trying so many options
)
LinkedHashMap<
String, String> paramLinkedMap = new LinkedHashMap<String, String>();
log.debug("b4");
try{
String data=null;
InputStream is = request.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte buf[] = new byte[1024];
int letti;
while ((letti = is.read(buf)) > 0)
baos.write(buf, 0, letti);
data = new String(baos.toByteArray());
log.debug("Data : " + data);
StringTokenizer st = new StringTokenizer(data, "&");
String token;
while(st.hasMoreTokens()){
token = st.nextToken();
paramLinkedMap.put(URLDecoder.decode(token.substring(0, token.indexOf("="))),
URLDecoder.decode(token.substring(token.indexOf("=")+1, token.length())));
}
}catch(Exception e){
}
log.debug("after");
Believe me i tried BufferRead, readline, char array but all in vain. Dont have enough reasons or logics to explain but this works fine. Tested
Moreover for those who are novice in using InputStream, if you use getParameter first, you will not get inputstream by calling getInputStream or a buffer reader by getReader().
Cheers,
Jay Rajani