Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Why is my sendRedirect/sendError/requestDispatcher not working??

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using TOmcat 4.0 as my web server. I've placed my Servlet inside webapps/examples/Web-INF/classes directory.
Here is the code snippet of my servlet:

public class ResponseRedirect
extends HttpServlet {
...
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();
//res.sendRedirect("greetings.html"); <-- not working even if greetings.html is inside the same directory as request URI
//res.sendRedirect("/greetings.html"); <-- not working even if greetings.html is in webapp directory
//res.sendError(res.SC_NOT_FOUND); <-- not working.
// If two lines below are used, getWriter above is commented.
// Code below is not working either
//RequestDispatcher rd = getServletContext().
getRequestDispatcher("/examples/servlet/HelloWorld");
//rd.forward(req,res);
} // doGet
...
}
I know I've tried that using JavaWebServer and it was working fine. How come it's not working in Tomcat?
Thank you very much for the help.
[This message has been edited by marlon tan (edited October 13, 2001).]
 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
You say that it's not working but you haven't given us any error messages to work with.
Do you get an IllegalStateException after this line?

If so its because you have uncommitted output in the buffer. According to the 2.2 specs - check with the 2.3 - before the target's service() method is called using the forward() method of the RequestDispatcher, the buffer must be reset.
Bye,

------------------
Terry Doyle
Sun Certified Programmer for Java 2 Platform
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic