Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher issue

 
Hazel Sisson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!
I'm trying to write a servlet that takes form data, validates it then sends some of that data to a JSP.
The problem is, the servlet uses a printwriter to inform the user of any mistakes they have made filling in the form, therefore I can't use the RequestDispatcher to send data to a JSP due to the output stream having already been used.
Does anyone have any idea how I could get round this?
Thanks very much,
Hazel
 
Mayer Salzer
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm assuming that you're trying to use both the PrintWriter (to report errors) and the RequestDispatcher (to send the rest of the data to the jsp) at the same time. What you can do instead is have some sort of error-page jsp, this way your error message can be sent through the RequestDispatcher as well, and you won't need the PrintWriter at all.
If you're worried that you won't be able to use the RequestDispatcher for more than one jsp, just call the RequestDispatcher's 'include' method. This method is used to call as many jsps (or other servlets) as you need. Each call to this method will keep appending to the bottom of the same output (page your user sees).
 
Hazel Sisson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great idea, why didn't I think of that?! :roll:
Thanks very much!
Hazel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic