File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clearing Request Parameters ?

 
James Gordon
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
When we submit a page using POST method, all the data on that page would be
available in the resulting JSP as well. Meaning if we would to do
a request.getParameterValues("var") in the JSP and "var" is a hidden fields
in the page submitted, we still have that value.
Is there a way to clear these data ?
We only need it in the servlet for processing, but after
that, it is not needed anymore. For request Attribute, there is a
removeAttribute method but not for parameter.
Reason as to why I want to clear it is that "var" might be a big array
and taking up lots of resources. Using GET is not an option for me
as I need to submit lots of data in the page, which is why the "var" is
huge.
Any comments?

Thanks in advance.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reason as to why I want to clear it is that "var" might be a big array and taking up lots of resources.

I don't know of any way to remove a request parameter, but there is really no reason to do it. All memory used by a request will be available for GC when the response is returned anyway. Servlets and JSP just naturally use lots of temporary objects, and the JVM is designed to efficiently recover the memory, particularly if you use the -server version.
Worry about getting your program architecture right, not about hypothetical performance details.
Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worry about getting your program architecture right, not about hypothetical performance details.

This should be emblazoned on a bronze plaque.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, whether you use a GET or POST method would make not one iota of difference. Why did you think that it would?
 
James Gordon
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
Yeah, GET method would give the same issue as well.
Actually, my concern is not really the resources used up
by the JVM.
But my application seemed to have problem forwarding to
a simple JSP for such a scenario. It took minutes to reach
that page though it is just plain html, no processing logic,
no tags.
Thus, I suspect that the parameters inside the request object would go
through "some sort of processing" during the requestDispatcher
forwarding. It won't happen when the request parameters
size is small.
If I can get the parameters cleared, may be the page forwarding
will be faster!
Please comment.

Thanks.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could call request.removeAttribute() on all attributes. That should clear them out, but the cost in processor time doing that by hand will likely outweigh the benefits unless you're extremely strapped for RAM.
AFAIK the request dispatcher doesn't do anything with the request parameters. Your performance problems sound more like server configuration problems leading to your server overloading from time to time.
Or maybe you're running into a memoryleak in your JSP engine which manifests itself some time after server restart (Tomcat has one related to the JSP compiler for example).
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looking at the source for the Tomcat implementation of RequestDispatcher, it appears that Jeroen is correct and it does not mess with request parameters. When in doubt, look at the source.
I'm sure your performance problem (minutes!!!) is due to something else. Is there a database involved?
Bill
 
James Gordon
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
removeAttribute can only take off those set using setAttribute.
If memory leak is a possible reason, could someone please some
me how to trace whether it does indeed happens?
And if it is configuration problem, then I can't really get it as
to why it won't happen when the parameters inside the request
object is not that big. Other modules are working fine as well.
And yes, database are involved. Got lots of insertions in my servlet
before forwarding to the JSP. Number of insertion depends on number
of items as reflected below. Insertions are done with a single connection,
so that I can rollback in case something goes wrong.
Below is a representation of the original form which
passed in some arrays parameters for processing in the servlets.
Amount 1 and Amount 2 has hidden fields as they are calculated
and re-calculating in the servlet would be redundant.
ITEM # | AMOUNT 1 | AMOUNT 2 | ...
1 | 10 | 10 | ...
2 | 20 | 20 | ...
The slow JSP forwarding would happens if I have around 60 items
submitted to the server.
submit slow forwarding
PREVIEW PAGE (above) -> SERVLET -> PLAIN HTML JSP.
I'm using connection pooling and I don't think I have unreturn connection
issue. I can trace it by printing out the total of connection checkout in
the resulting JSP.
Please comment.

Thanks.
 
James Gordon
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Flow diagram not correctly displayed above.
PREVIEW PAGE (above) -> SERVLET -> PLAIN HTML JSP.
submit = between Preview page and Servlet.
slow forwarding = between Servlet and Plain Html Jsp.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic