>Hi, Ben:
>Thanks for your inputs.
>1.� How can I redirect post data to server2?�
>2.� How can I store the entire original HttpServletRequest (on server 1) into a distributed HttpSession?� Aren't they still on server1?� Or, Are you suggesting me to use RMI?
>3.� What do you mean by make a container class for all data?
>Sorry, I don't have much experience on Java Servlet.� Some sample codes will help me a lot.
>Thanks,
>������� Jackie
1. Try something like this in service():
StringBuffer buff = new StringBuffer("");
String names[] = req.getParameterNames();
for (int i=0; i<names.length; i++) {
String values[] = req.getParameterValues(name[i]);
for (int j=0; j<values.length; j++) {
if (buff.length() > 0) {
buff.append("&");
}
buff.append(URLEncoder.encode(name[i]));
buff.append("=");
buff.append(URLEncoder.encode(value[j]));
}
}
StringBuffer redirecturl = new StringBuffer("http://server2/servlet");
redirecturl.append("?");
redirecturl.append(buff);
res.sendRedirect(redirecturl.toString());
This will take all your form parameters and convert them into an HTTP GET request (i.e. http://xxx.yyy.zzz/nnn?name1=value1&name2=value2...).
2. It depends on your servlet implementation -- some support distributed sessions. If not, you're absolutely right, you'll have to use something like RMI to transfer the data to the other machine.
3. #1 should work in most cases, but there may be times when you need to access more than just form data (perhaps cookies, or HTTP headers, or something else). In this case, #1 won't provide all the information you need. One solution is to put the information into the URL you construct in #1 and pretend they're form variables. Another is to put them in any kind of Serializable object and store them in the session described in #2.
Hope that's clearer,
Ben
--
Ben Engber
Software Engineer
The New York Times
[EMAIL PROTECTED]
___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
- Need some inputs Jackie Chang
- Re: Need some inputs Ben Engber
- Re: Need some inputs Niall Smart
- Re: Need some inputs Jackie Chang
- Ben Engber
