This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

RequestDispatcher issue  RSS feed

 
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
 
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!