• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mapping servlets

 
santosh akella
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
basically i have servlets for checking authentication, for showing the list of messages, and displaying messags

i want all these servlets to open in a chain...
so, how could i perform this task
thanq
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RequestDispatcher.forward() is your friend.
 
santosh akella
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi jeroen

when i used RequestDispatcher , this the error it is showing while running
"Can't forward! OutputStream or Writer has already been obtained."

thanq
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, once you get a reference to the output you can no longer forward the request as you've already started sending data to the client.

Most proper way to work is to collect all data you need to send and then send that all in one go (or forward to somewhere else instead).

If you may need to forward never open the outputstream (or its writer which implicitly opens the stream) until you can be certain you will not be forwarding.

Forgot to mention that as my servlets (except in very rare conditions which always can appear only on the end of pipes) never write to the output but always forward to another resource (either a JSP or another servlet).
I've not had HTML generation in a servlet for 5 years
 
santosh akella
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WELL I GOT A SOLUTION FOR THIS ONE
AS I AM WRITING pw.println("<a href='http://localhost:8080/servlet/display(displaying servlet)?folder="+name+"'>"+name+"</a>");
where name the string which takes INBOX.....as per the program..
now it is connecting to the other servlet...
is this the correct way and there other way around...
thanq
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that just puts a link to the other page onto the html you're generating, it doesn't cause it to go there.
 
Paul Frey
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't a Filter be a better solution here?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!