httpservletresponse

GZip HttpResponse using XSL Transformer - Java

I have the following code below in my Servlet, but when IE hits the page, it returns a blank html page. If I use the response.getOutputStream() directly in the StreamResult constructor, the page loads fine. What am I missing? response is an instance of HttpServletResponse and xsl is an instance of Transformer from XSLTC TransformerFac...

How can I get the HTTP status code out of a ServletResponse in a ServletFilter?

I'm trying to report on every HTTP status code returned from my webapp. However the status code does not appear to be accessible via the ServletResponse, or even if I cast it to a HttpServletResponse. Is there a way to get access to this value within a ServletFilter? ...

Ajax Requests again

hi, I have again a problem with my ajax requests. my architecture hasn't change, so I use a Java servlet on the server side, and on the client I'm running a JavaScript application, programmed and tested with firefox. In firefox I also installed firebug, because it's very comfortable to watch the incoming and outgoing ajax requests. howe...

Logging response body (HTML) from HttpServletResponse using Spring MVC HandlerInterceptorAdapter

I am trying to log (just to console write now for simplicity sake) the final rendered HTML that will be returned by the HttpServletResponse. (i.e. the body) To this end, I am using the HandlerInterceptorAdapter from Spring MVC like so: public class VxmlResponseInterceptor extends HandlerInterceptorAdapter { @Override public void...

Mimic an HTTPRequest and HTTPResponse object in Java

How do I mimic an HTTPServletRequest and HTTPServletResponse object. The reason is I want to test the behaviour of some servlets. I know JUnit probably provides this functionality but I don't know how to use it (I will learn soon) and need to do this reasonably quickly. HTTPServletRequest and HTTPServletResponse are both interfaces so ...

Is calling HttpServletResponse.addCookie() with the same cookie name safe?

Is calling HttpServletResponse.addCookie(); (from servlet-api-2.5) multiple times using a cookie with the same name safe? Safe in the sense of that there is a deterministic behavior, e.g. the subsequent calls will be ignored (the first wins) or the subsequent calls will always replace the cookie or something like that? Example: H...

Java Applet - Download File with Browser

Hello! I'm trying create a new file with a Java Applet, but I don't know how send this file to the response output of the browser, such as any tipical webpage. With a Servlet it is easy with "HttpServletResponse response", but is this possible with a applet? I'm trying do this without sign the applet or use any servlet. Thanks a lot!...

response.setContentType() always trim the space between "; charset" ?

Hi, I'm using Tomcat 6.0.20, HttpServlet my servlet code are as followings :- response.setContentType("application/xml; charset=utf-8"); but each time i will got the content type as : application/xml;charset=utf-8 which is without the space between " ; ". May i know how to bypass the space being trimmed? Is there anyway to do s...

Redirecting Servlet to Unicode-Domains

I'm having problems with sending redirections to servlet with Unicode-URLs. i.e. consider the following url in Turkish http://türkçeisimtescil.com It works if you paste it into your browser's address bar. However it is translated to http://xn--trkeisimtescil-ijb74a.com by your browser upon your request. Let's say I have fir...

Is there any way to read cookies from the response object in Java?

It doesn't seem that HttpServletResponse exposes any methods to do this. Right now, I'm adding a bunch of logging code to a crufty and ill-understood servlet, in an attempt to figure out what exactly it does. I know that it sets a bunch of cookies, but I don't know when, why, or what. It would be nice to just log all the cookies in ...

How to retrieve a JSON object from HttpServletResponse in Spring?

I have a Spring controller in which I have to read a JSON object from a URLConnection. Currently I am doing this by reading from the connection's input stream line by line. Basically I am reading the text contents of the response line by line. Is there any JSON api that I could use to populate the JSON object directly from the URLConnec...

Is it possible to invoke a javaScript server side ?

greetings all i was wondering if it's possible to send some javaScript code in the response of a controller meaning that i want to invoke a javaScript but not from the jsp (from server side) something like: var d = new Date(); var gmtHours = -d.getTimezoneOffset()/60; var tz=gmtHours; window.location="page?tz="+tz; what do you think g...

JAVA servlets - open message popup

I want to user HttpServletResponse object to compose a response that will tell the browser client to open a popup with some message - how can i do that? ...