Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect() - Servlet path

 
Bala Krishniah
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic