• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to return http response without creating html output

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all
im using tomcat as servlet container and http listener , i have client application that notify with http post requests to
the server (tomcat ) when i capture the request im trying to return the client response but all i success to return is
the
PrintWriter out = response.getWriter();
out.println(" ").....and got print the content of the response to the html my question is how can i response directly to the client ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you're asking but if you want to send back an empty response, don't bother creating a print writer.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not empty ,
for example i like to return text response that says :
"foo=1"
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't understand the question.
Can you elaborate a little more?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The response doesn't need to be HTML; it can be plain text or anything else the client can handle.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah but it still will be printed to the page.
i don't want it . i like tomcat will be just simple http listener
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you initiate the request with a browser, the response will be returned to the browser. If you want something else you're going to have to give a lot more information than you have on what you are actually trying to do.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What prevents you from returning a 0-size response? HTTP is a request/response protocol; you can't have one without the other, or you'll confuse the client and/or the server.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the info
my client is c client that construct the http request and send it
via winsock send to the ip ort ( that is the tomcat listener )
im not using the browser to send the request .
in the server i have simple servlet ( mybe this is my problem ...)
that capture the http request via doPost and return me response.
thats all .
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll ask again: What prevents you from returning a 0-size response and ignoring it in the client? If for some reason you absolutely, positively can't have a response, then HTTP is not the right communication channel.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you mean by 0-size response ?
i do need to build response string.
i can ignore if i have no way other then that .
 
marten kay
Ranch Hand
Posts: 178
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this helps Meir

but an alternative to
PrintWriter out = response.getWriter(); out.println(" ").. for text/html

is

ServletOutputStream out = response.getOutputStream(); out.write(Byte); for other mime types. You need to set the response.setContentType ("") though, and your c client needs to be able to handle the content type that is set.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, don't bother getting a printWriter.
In other words, as Ulf said, don't return anything in the body.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic