tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: How to programmatically add parameters to ServletRequest objects?
Date Thu, 07 Aug 2008 14:15:14 GMT
Hash: SHA1


Jonathan Mast wrote:
| | This is really the only way to do it. The other option is to create a
| | new request object and stuff your own parameters into it (or, better
| | yet, wrap the original request and add your parameters only to the
| wrapper).
| How would I do this?  This is basically what Jakarta Commons HTTPClient
| package (org.apache.commons.httpclient.*) offers, correct?

I'm pretty sure you don't want HTTPClient.

What you'd do is write your own new class called something like
AdditionalParameteHttpServletrsRequest and extend
HttpServletRequestWrapper. Override all methods that deal with
parameters and add your own parameters when appropriate.

| I thought such manipulation would be achievable without additional

It is. You just have to write some of your own code.

| | Why do you believe that adding parameters to the URL is not scalable?
| Well, its not scalegent, to coin a term;
| String munging is expensive (scalability), and
| StringBuffer sb = new StringBuffer();
| is rough to look at (elegent).

String munging will be done whether you code it yourself or you delegate
it to some other utility (such as the JSP's version of the same code, or
to HTTPClient, or whatever).

If you don't want to look at the code, put it into a utility method with
an interface like MyParameterUtility.addParameter(String nanme, String
value). That will also give you the opportunity to properly URI-escape
both the parameter names and values.

| Why not just:
| HashMap myParams = new HashMap();
| myParams.put("foo", bar);
| ...
| pageContext.forward("page.jsp", myParams)   ?

Because that's not part of the interface, unfortunately. Feel free to
lobby a member of the JCP to add that method to the RequestDispatcher
(PageContext is a bad place to put something like that).

| much more efficient and elegent, imho.

No, it just hides the code you don't like to see behind an interface.
You are perfectly capable of writing an interface such as that: I
suggest you do it. <shrug>

- -chris
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla -


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message