
- •По курсу «Интернет-программирование»
- •Принципы построения интернет-приложений на Java
- •Сервлеты (Servlet) и jsp
- •Сервлеты
- •Синтаксис jsp-страницы
- •Комментарии
- •Директивы
- •Объявления
- •Выражения
- •Скриплеты
- •Объекты request, response, cookie, session
- •Загрузка файлов на сервер
- •Объект request
- •Объект response
- •Объект cookie
- •Объект session
- •Приложение 2
Объект response
Method |
Description |
String encodeRedirectURL(String url) |
Encodes the URL in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. |
String encodeURL(String url) |
Encodes the URL by including the session ID, or, if encoding is not needed, returns the URL unchanged. |
boolean containsHeader(String name) |
Returns a boolean indicating whether the named header has been set. |
boolean isCommitted() |
Returns a boolean indicating if the response has been committed. |
void addCookie(Cookie cookie) |
Adds the cookie to the response. |
void addDateHeader(String name, long date) |
Adds a response header with the given name and date-value. |
void addHeader(String name, String value) |
Adds a response header with the given name and value. |
void addIntHeader(String name, int value) |
Adds a response header with the given name and integer value. |
void flushBuffer() |
Forces content in the buffer to output to the client. |
void reset() |
Clears data in the buffer, the status code and headers. |
void resetBuffer() |
Clears the buffer content in the response without clearing headers or status code. |
void sendError(int sc) |
Sends an error response to the client with the specified status code and clear the buffer. |
void sendError(int sc, String msg) |
Sends an error response to the client using the specified status. |
void sendRedirect(String location) |
Sends a temporary redirect response to the client using the specified redirect location URL. |
void setBufferSize(int size) |
Sets the preferred buffer size for the response body. |
void setCharacterEncoding(String charset) |
Sets the character encoding of the response, for example, to UTF-8. |
void setContentLength(int len) |
Sets the length of the content body in the response(HTTP Content-Length header). |
void setContentType(String type) |
Sets the content type of the response, if the response has not been committed yet. |
void setDateHeader(String name, long date) |
Sets a response header with the given name and date-value. |
void setHeader(String name, String value) |
Sets a response header with the given name and value. |
void setIntHeader(String name, int value) |
Sets a response header with the given name and integer value. |
void setLocale(Locale loc) |
Sets the locale of the response, if the response has not been committed yet. |
void setStatus(int sc) |
Sets the status code for this response. |
Объект cookie
Method |
Description |
setDomain(String pattern) |
sets the domain for cookie, for example java2s.com. |
String getDomain() |
gets the domain to which cookie applies. |
setMaxAge(int seconds) |
Sets how much time in seconds should elapse before the cookie expires. By default, the cookie will last for the current session. |
getMaxAge() |
Get cookie age in seconds. -1 indicating the cookie will persist until browser shutdown. |
String getName() |
returns the name of the cookie, which cannot be changed after creation. |
setValue(String newValue) |
sets the value associated with the cookie. |
String getValue() |
gets the value associated with the cookie. |
setPath(String uri) |
sets the path this cookie applies. By default, the cookie is returned for all URLs in the current directory and subdirectories. |
String getPath() |
gets the path to which this cookie applies. |
setSecure(boolean flag) |
sets to send cookie over encrypted (i.e. SSL) connections. |
setComment(String purpose) |
Sets a comment that describes a cookie's purpose. |
String getComment() |
get the comment for the cookie |