This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to get the parameters of servletRequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get the parameters of servletRequest" Watch "How to get the parameters of servletRequest" New topic
Author

How to get the parameters of servletRequest

Howard Zhao
Greenhorn

Joined: May 06, 2002
Posts: 27
Hi
I am having a question on getting the parameters and values from a servletRequest.
Because I have to send more than 100,000 parameters & value pairs back to servelt after the applet finishes processing the data, (cause the applet must send the results back to servlet and then, the servlet can save the updated data to a database), in order to save the net work transfer time, I use gzip to zip the servletRequest query string. Everything is fine during at the networks, but when the servlet wants to process the query string, it has no way to get all the parameters & value pairs back cause the gzip has changed the query string. I mean I can restore the query string back to a string, but the restored string is not the same the query string any more. I have the same parameters & value pairs, but I am not able to retrieve the parameters (values) using request.getParameter()(request.getParametersValue()).
Is there any way such that I can put a string which has parameters & value pairs into a servletRequest object so that I can use request.getParameter() or request.getParametersValue() methods?.
BIW, how was the servletRequest implemented? Is there a way that I can view the source code?
Thanks.
Have a nice weekend.
Howard
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi howard,
i am surprised how u do zip on the querystring! can u tell me how to do it if we want? an example code will be a great thing to post for this...
COMING TO UR PROBLEM,
why dont' u put all ur name/value pairs in say Properties object and then zip that object and unzip at the servlet side again?
if u can do that then ur problem can be solved i guess..
also, please try to post zip/unzip code to give me the idea how it works...
regards
maulin.
lakshmi rajagopal
Greenhorn

Joined: Jun 22, 2002
Posts: 5
i don't know why you are trying to put the string again into a servelet request object.directly you can tokenise the name=value pairs using the delimeter & and process them. what will be the difficulty with that for you?


lakshmi
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
Excuse me but if you have to send 100,000 parameters in a request to a servlet you may have to rethink your design.
I have no idea what you want to do but shouldn't you consider sending a compound object (a HashMap maybe?) via one of the Streams, to the server from the applet?
Just a thought...


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
kris reddy
Greenhorn

Joined: Nov 07, 2000
Posts: 19
May be you want to try using a URL connection to connect the applet and the servlet and pass data as a stream using the connection.
Kris.


Kris Lee
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi
the question here seem not "how to pass the params" but how to make those COMPRESSED and then pass...
thats what understand...
correct me if i'm wrong..
regards
maulin
Howard Zhao
Greenhorn

Joined: May 06, 2002
Posts: 27
Dear All
Thank you very much for the quick replies.
TO Maulin:
The zip/unzip is pretty easy. Since I am not the only guy who is in the project. I am afraid I can not post the zip/unzip code here since this piece of code was developped by my team-mates. But I can give you a hint. It is somthing like GZIPInputStream stream, then stream.toStrin(). I hope you can understand me, and hope that this post can help you.


TO Lakshmi
Using tokens to parse the request string is a common idae. But I am wondering, maybe by using tokens, the processing speedm will be lower than the speed of derectly using request.getParameterValues(), especially when the string is very long (with a length of over 1,000,000) and each token is pretty samll (with a length less than 10). Actually I am using tokens, but the problem is that I need to retrieve the data (tokens) quickly and to allow my servlet use not much memory. The key point of my question is that if possible, I want to know how the methods(request.getParameterValues(), request.getParameter(), ..) are implemented, and what kind of datastructure and algorithm are used.

To Tony
I think setting up a hashtable at client side is not feasible in my case coz the hashtable will lower the proccessing speed and increase the client side memory usage. I will use a hashtable at the server side for sure.

To Kris
Right!!! it is a stream and zipped.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get the parameters of servletRequest
 
Similar Threads
How to send Key/Value pair bak to Servlet from Struts??
Alternative to parseQueryString
Differences Between doGet(),doPost(),service()
confused between attributes and parameters
Better way to send a http response