A
autogoor
We have a couple of online resources (cgi, servlet...) on different
machine and even different domains. For example, user can call
http://www.domain1.com/app1&name="smith"
or
http://www.domain2.com/cgi-bin/app2&zip="94000"
and get response.
We would like to provide a central location which can take user's
request and forward them to appropriate destinations. Thus, if user
call:
http://www.centeral.com/mainapp?app=app1&name="smith"
The request will be forwarded to the first service.
I am writing a servlet which basically check user's authorization and
they forward the request with user's original parameters to other
resources.
Here is my code for centeral/mainapp:
public class MainAppServlet extends HttpServlet{
private static final String s1="http://www.domain1.com/app1";
private static final String
s2="http://www.domain2.com/cgi-bin/app2";
private static final String s3="http://www.domain3.com/app2";
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
//check if user loged in
...
//forward
String app = request.getParameter("app");
String des;
if ("app1".equals(app)){
des = s1;
}
if ("app2".equals(app)){
des = s2;
}
if ("app3".equals(app)){
des = s3;
}
response.senRequestDispatcher dispatcher =
request.getRequestDispatcher(des);
dispatcher.forward(request, response);
}
}
We found the code did not work. I think it is because "forward" can
only handle request to the same server. How can I fix it? I am thinking
about sendRedirect, but how can I forward parameters with it?
Thanks,
Autogoor
machine and even different domains. For example, user can call
http://www.domain1.com/app1&name="smith"
or
http://www.domain2.com/cgi-bin/app2&zip="94000"
and get response.
We would like to provide a central location which can take user's
request and forward them to appropriate destinations. Thus, if user
call:
http://www.centeral.com/mainapp?app=app1&name="smith"
The request will be forwarded to the first service.
I am writing a servlet which basically check user's authorization and
they forward the request with user's original parameters to other
resources.
Here is my code for centeral/mainapp:
public class MainAppServlet extends HttpServlet{
private static final String s1="http://www.domain1.com/app1";
private static final String
s2="http://www.domain2.com/cgi-bin/app2";
private static final String s3="http://www.domain3.com/app2";
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
//check if user loged in
...
//forward
String app = request.getParameter("app");
String des;
if ("app1".equals(app)){
des = s1;
}
if ("app2".equals(app)){
des = s2;
}
if ("app3".equals(app)){
des = s3;
}
response.senRequestDispatcher dispatcher =
request.getRequestDispatcher(des);
dispatcher.forward(request, response);
}
}
We found the code did not work. I think it is because "forward" can
only handle request to the same server. How can I fix it? I am thinking
about sendRedirect, but how can I forward parameters with it?
Thanks,
Autogoor