What is the difference between setheader and addheader methods




















Support Us BTC address link. We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. Do not sell my personal information. Cookie Settings Accept. Manage consent. Close Privacy Overview This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website.

We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.

Necessary Necessary. Necessary cookies are absolutely essential for the website to function properly. String name Returns a boolean indicating whether the named response header has already been set.

String encodeRedirectUrl java. String url Deprecated. As of version 2. String encodeRedirectURL java. String encodeUrl java. String encodeURL java. String getHeader java. String name Gets the value of the response header with the given name. String name Gets the values of the response header with the given name.

String msg Sends an error response to the client using the specified status and clears the buffer. String location Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer. String name, long date Sets a response header with the given name and date-value. String value Sets a response header with the given name and value.

String name, int value Sets a response header with the given name and integer value. String sm Deprecated. To set a status code use setStatus int , to send an error with a description use sendError int, String. Sets the status code and message for this response. Methods inherited from interface javax. This definition is being retained for backwards compatibility. Since the redirection might be altered on occasion, the client should continue to use the Request-URI for future requests.

This method can be called multiple times to set more than one cookie. Parameters: cookie - the Cookie to return to the client containsHeader boolean containsHeader java. Parameters: name - the header name Returns: true if the named response header has already been set; false otherwise encodeURL java.

The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary. For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

Parameters: url - the url to be encoded. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separated from the encodeURL method. See Also: sendRedirect java. Here is the sample servlet code I wrote to experiment: import javax. Entry iter. Appreciate very much. Anand SCJP1. Anand Can you please tell us the servlet container on which you ran this program. Thank you.

Todd Farmer. I don't know about Anand, but I am using Tomcat 5. Praveen Kumar Mathaley. I understand the distinction between addHeader and setHeader , which is why I also don't understand the behavior observed. Shouldn't the "h1" header be "new v1" only instead of a "new v1", "v2" and "v3"? Instead of overwriting the "h1" header values entirely, it appears to replace just the first of the three values.

I added another setHeader to the example, and again, it only overwrote the first "h1" header value: response. Rafael Pereira. Why don't you use the following code from Tomcat 5. I guess I still don't understand the distinction being made. Regardless of the mechanism used to capture the HTTP headers returned from the servlet, I still don't understand why the original values of the "h1" header are not being discarded when setHeader is used.

I look at it as if the header values are being maintained in a ArrayList. But when setHeader name, value is called, we get behavior like: ArrayList. My expectation, from reading HFS, is that we would get the results comparable to the following: ArrayList. But that's not what I'm seeing. For this problem, it's still open!

From Todd's addition, seems like setHeader replaces only first value of the header replacing only first element of arraylist. Thank you very much Todd for your effort.



0コメント

  • 1000 / 1000