aspose file tools*
The moose likes Servlets and the fly likes how to return http response without creating html output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to return http response without creating html output" Watch "how to return http response without creating html output" New topic
Author

how to return http response without creating html output

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
not empty ,
for example i like to return text response that says :
"foo=1"
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I still don't understand the question.
Can you elaborate a little more?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41833
    
  63
The response doesn't need to be HTML; it can be plain text or anything else the client can handle.


Ping & DNS - my free Android networking tools app
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
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

Joined: Jan 10, 2002
Posts: 61202
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41833
    
  63
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

Joined: Apr 27, 2006
Posts: 597
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
Marshal

Joined: Mar 22, 2005
Posts: 41833
    
  63
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

Joined: Apr 27, 2006
Posts: 597
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

Joined: Feb 03, 2007
Posts: 178

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.


when in doubt put it in parenthesis and stick a dollar sign in front of it, only good can come from this.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Again, don't bother getting a printWriter.
In other words, as Ulf said, don't return anything in the body.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to return http response without creating html output