File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forward Question

 
Isaias C. Barroso
Ranch Hand
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
How to forward a servlet on a different context?
Context - > test1 -> ServletTest1
Context - > test2 -> ServletTest2
On ServletTest1 i want forward a ServletTest2.
getServletContext().getRequestDispatcher("/test2/servlet/ServletTest2").forward(req, res);
Don't work.
Best Regards,
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on how well it is implemented on the server you are using (it isn't always useful), this is possible but not a good idea.
The reason it's a bad idea is that it creates dependencies between your applications. A context should be a stand-alone application. If you need the servlet, it may be better to import it into the context and give it its own mapping.
That said, this may work:
getServletContext().getContext( "test2" ).getRequestDispatcher("/servlet/ServletTest2").forward(req, res);
The call to 'getRequetDispatcher' is always specific to a context, which is why your call didn't work. This reaches from one context to the next and makes method calls from that context.
Depending on the sever you are using, you might need "/test2" rather than "test2".
Dave
 
Isaias C. Barroso
Ranch Hand
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
Thanks by response.
Best Regards.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sent by chandm
I quoted your reply to a previous post and I wanted to ask you what you meant. I have been creating Web application which send control over to a servlet, the servlet does some work and uses RequestDispatcher.forward to send a JavaBean and the request to a JSP page. The thing is it fails a lot after using a stress tool to test it out. Is this attributed to what your stating below and the better way you offer is that using RequestDispatcher.include. Does that make it stay in the same context?
Thanks.

If you aren't explicitly calling a different context then you always remain in the same one. If you are crossing contexts then you are likely to have a range of problems depending on the server you are using.
One possible problem I forgot to mention is that of thread safety. When you cross between contexts, it may be that you get assigned a different thread in the other context. If this is the case then code may not execute in the order you expect, and Objects that you though were safe may be altered by different threads at the same time. This could certainly cause problems during load testing.
I can't really say more without specific information of whats going on.
Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Isaias C. Barroso:
Hi David,
Thanks by response.
Best Regards.

No problem, I hope it helped!
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic