aspose file tools*
The moose likes Servlets and the fly likes sendRedirect() - Servlet path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "sendRedirect() - Servlet path" Watch "sendRedirect() - Servlet path" New topic
Author

sendRedirect() - Servlet path

Bala Krishniah
Ranch Hand

Joined: Dec 14, 2000
Posts: 81
I am using a sendRedirect() method in my servlet to redirect to another servlet....
(1) sendRedirect(web/client/myServlet);
This works on my test machine.
But on the servler this path doent work, I need to say
(2) sendRedirect(myServlet);
I really dont know where to look for in my application to correct this. I need to call the method as in (2) in my test machine too. What should I do??
Mark Simms
Ranch Hand

Joined: Jul 20, 2000
Posts: 36
Looks as though your web application's docBase may have changed ?
sendRedirect has the problem in Servlet 2.2 where no RELATIVE context references are permitted.....my feeling is there are other limitations as well.
Here is code that I use to insure the proper URL construction before the redirect:
// place in the doPost/doGet method
String sRedirect = getDefaultRedirectUrl(request);
int i = sRedirect.indexOf("//"); i = sRedirect.indexOf("/",i+2);
// below returns "http://localhost:8080"
String proto_host = sRedirect.substring(0,i+1); // find the first "/" to catch the host and protocol
cont_path = request.getContextPath();
if (cont_path.equals("")| |cont_path.equals(null)| |cont_path.equals(" ")) {cont_path = proto_host;}
sRedirect = addActionToUrl(cont_path + CONFIRMATION_JSP, sLoanId);
response.sendRedirect(sRedirect);
Of course the above is for a redirect to a JSP.....but you should get the picture.
addActiontoURL can be replaced by a simple Stringbuffer append.

Mark
 
wood burning stoves
 
subject: sendRedirect() - Servlet path
 
Similar Threads
Forwarding request to same servlet
Clarification abt init()
welcome file for virtual/logical path
Cactus question
I want to make static URL