• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Disable Auto Servlet PrintWriter

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you disable the PrintWriter that is automatically obtained in a servlet with an empty service method.
public class Example extends HttpServlet
{
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
/* Calculate some things, Do not send any output */
}
}
I run this servlet and get output. How do I disable all output?
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What output do you get? This is a very strange thing to want to do - can you elaborate on why you are using servlets for this, and what you expect a browser to do if it gets no response from the server?
 
Warren Bell
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two servlets and one jsp. The first servlet includes the second. The second servlet does some processing. The first servlet then forwards to the jsp. The forward is not working because the second servlet has automatically obtained a PrintWriter. I am getting an IllegalStateException. I have narrowed it down to the included second servlet. I have tested the second servlet by itself with an empty service method. It still produces output e.g. headers and some basic html. This output is what is getting in the way of the forward call. I am including and forwarding using the following code:
RequestDispatcher d = getServletContext().getRequestDispatcher("/filename");
d.include(request, response);
or
d.forward(request, response);
Any help will be greatly appreciated.
Warren Bell
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your servlet doesn't need to generate any output, why is it a servlet? Surely you could implement that functionality in a regular Java class which you call from your first servlet.
 
Warren Bell
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is exactly what I ended up doing.
Thanks for your help.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic