| Author |
RequestDispatcher issue
|
Hazel Sisson
Greenhorn
Joined: Feb 12, 2002
Posts: 17
|
|
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
Joined: Apr 01, 2002
Posts: 20
|
|
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).
|
Sun Certified Programmer for Java 2 Platform
|
 |
Hazel Sisson
Greenhorn
Joined: Feb 12, 2002
Posts: 17
|
|
Great idea, why didn't I think of that?! :roll: Thanks very much! Hazel
|
 |
 |
|
|
subject: RequestDispatcher issue
|
|
|