T
Terry
Hello,
I've been unable to solve a servlet problem. I hope this group can
offer some ideas.
I have several servlets that accepts only post data. Depending on
business logic, a servlet may need to redirect to another page on
another site with only the address of the servlet appended to the query
string so that the outside page can post back to the servlet. This
seems like an unusual design - it's not mine, but I'm stuck with it.
Here's where it gets tricky. If a servlet does need to redirect to an
outside site, it must first store the original request parameters. When
the outside site posts back, it can discard completely anything sent
from that site, but it needs to reinstate the original request
parameters in the current request object and resume processing.
I can use session variables and cookies, but cannot write to a file or
to a database. The original request parameters will usually be less
than 1kb in size, but could be as large as 8 Kb in some rare cases.
I've approached the problem like this: I have a utility object with one
method. The method is called as the first line of doPost() by each
servlet that needs to implement this functionality. This method takes
two parameters: the request and response passed to doPost(). If the
method determines the servlet does not need to redirect, it simply
returns and the servlet resumes processing. If the method determines
the servlet must redirect, it first calls getParameterMap() on the
request, then stores the returned map in a session variable. It then
calls the response object's sendRedirect() method to send the browser to
the outside page. When the page posts back (usually within seconds),
the servlet again calls the utility object's single method as the first
line of its code, again passing it the request and response objects of
the doPost method. This time, the method looks for and finds the
original request parameters stored as a map in a session variable. It
retrieves the map, then deletes the session variable.
Now, what I want to do is to have the request contain the original
parameters so that when the method returns, the servlet can continue
processing as though it never left. I can set *attributes* in the
request via setAttribute(), but it doesn't seem possible to set
*parameters*. There's nothing valuable in the post back from the
outside site, so I can change it all I want, so long as at the end, the
servlet can continue processing with the original request parameters.
I've thought about storing the whole request object in a session and
replacing the request from the outside site with the original, but since
Java passes object references by value, swapping the request object
inside the method has no effect once the method returns to doPost(),
which is where I need the request to have the original parameters.
I suspect Java has a far more eloquent mechanism for accomplishing what
I want to do, I'm just not aware of it.
Any ideas? Thanks in advance for your feedback.
--Terry.
I've been unable to solve a servlet problem. I hope this group can
offer some ideas.
I have several servlets that accepts only post data. Depending on
business logic, a servlet may need to redirect to another page on
another site with only the address of the servlet appended to the query
string so that the outside page can post back to the servlet. This
seems like an unusual design - it's not mine, but I'm stuck with it.
Here's where it gets tricky. If a servlet does need to redirect to an
outside site, it must first store the original request parameters. When
the outside site posts back, it can discard completely anything sent
from that site, but it needs to reinstate the original request
parameters in the current request object and resume processing.
I can use session variables and cookies, but cannot write to a file or
to a database. The original request parameters will usually be less
than 1kb in size, but could be as large as 8 Kb in some rare cases.
I've approached the problem like this: I have a utility object with one
method. The method is called as the first line of doPost() by each
servlet that needs to implement this functionality. This method takes
two parameters: the request and response passed to doPost(). If the
method determines the servlet does not need to redirect, it simply
returns and the servlet resumes processing. If the method determines
the servlet must redirect, it first calls getParameterMap() on the
request, then stores the returned map in a session variable. It then
calls the response object's sendRedirect() method to send the browser to
the outside page. When the page posts back (usually within seconds),
the servlet again calls the utility object's single method as the first
line of its code, again passing it the request and response objects of
the doPost method. This time, the method looks for and finds the
original request parameters stored as a map in a session variable. It
retrieves the map, then deletes the session variable.
Now, what I want to do is to have the request contain the original
parameters so that when the method returns, the servlet can continue
processing as though it never left. I can set *attributes* in the
request via setAttribute(), but it doesn't seem possible to set
*parameters*. There's nothing valuable in the post back from the
outside site, so I can change it all I want, so long as at the end, the
servlet can continue processing with the original request parameters.
I've thought about storing the whole request object in a session and
replacing the request from the outside site with the original, but since
Java passes object references by value, swapping the request object
inside the method has no effect once the method returns to doPost(),
which is where I need the request to have the original parameters.
I suspect Java has a far more eloquent mechanism for accomplishing what
I want to do, I'm just not aware of it.
Any ideas? Thanks in advance for your feedback.
--Terry.