▶ HttpServletRequest 인터페이스
- ServletRequest으로 부터 상속받는 인터페이스로서 웹 클라이언트로 부터 전달되는 요청을 표현하기 위해서 사용된다.
- 웹 클라이언트(웹 브라우저)로 부터 전달되는 모든 정보는 HttpServletRequest 인터페이스를 통해서 얻을 수 있다.
- HttpServletRequest 인터페이스를 구현한 클래스는 웹 컨테이너에서 제공하기 때문에 개발자는 인터페이스에 제공하는
메소드를 이용해서 프로그램을 작성한다.
⑴ HttpServletRequst 인터페이스 메소드
[HttpServletRequest 인터페이스의 일반적인 메소드]
① public java.lang.String getAuthType()
서버가 사용하는 인증(Authentication) 이름(예: "BASCI" , "SSL" ,"null")을 리턴한다.
Returns the name of the authentication scheme used to protect the servlet.
All servlet containers support basic, from and client cerificate authentication, and may additionally support digest
authenticatiion. If the servlet is not authenticated null is returned.
Same as the value of CGI variable AUTH_TYPE.
Returns:
one of the static members BASIC_AUTH, FROM_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH(suitable for == comparsion)
or the container-specific string indicating the authentication scheme, or null if the request was not authenticated.
② public Cookie[] getCookie()
브라우저가 요청과 함께 전달한 쿠키들을 얻어 온다.
Returns an array containing all of the Cookie object the client sent with this reqeust.
This method returns null if no cookie were sent.
Returns:
an array of all the Cookies included with this request, or null if the reqeust has no cookies
③ public java.lang.String getHeader(java.lang.String name)
주어진 이름의 요청 헤더(Request Header) 값을 얻어 온다.
Returns the value of the specified reqeust header as a String.
If the reqeust did not include a header of the specifed name, this method returns null.
If there are multipe headers with the same name, theis method returns the first heade in ther request .
THe header name is case insensitive. You can use this method with an y request header.
Parameter:
name - a String specifying the header name
Returns:
a String containing the value of the requested header, or null if the request does not have a header of the name
④ public java.lang.String getMethod()
Http의 명령어( 메솧드) 이름(예: GET, POST, PUT)을 얻어 온다.
Returns t he name of the HTTP method with which this request was made, for, example, GET, POST or PUT.
Same as the value of the CGI variable REQUEST_METHOD.
Returns:
a String specifying the name of the method with which this request was made
⑤ public java.lang.String getPathInfo()
URL에서 추가적인 패스 정보를 얻는다.
Returns an yextra path information associated with the URL the client sent when it made this request.
The extra path information follows the servlet path but precedes the query string and will start with a "/" character.
Same as the value of the CGI variable PATH_INFO.
Returns:
a String , decoded by the web container, specifying extra path information that comes after the servlet path but
before the query string in the request URL; or null if the URL does not have any extra path information
⑥ public java.lang.String getPathTranslated()
서블릿 이름에서 부터 쿼리 스트링(Query String) 전까지의 추가적인 패스 정보를 얻어 온다.
Returns any extra path information after the servlet name but befor the query string , and translated it to a real path.
Same as the value of the CGI variable PATH_TRANSLATED.
if the URL does not have any extra path information, this method returns null or the servlet container cannot translate
the virtual path to a real path for any reason (such as when the web application is executed from an archive).
The web container does not decode this string.
Returns:
a String specifying the real path, or null if URL does not have any extra path information
⑦ public java.lang.String getRemoteUser()
HTTP 인증을 통해 로그인한 사용자의 이름을 얻어 온다.
Returns the login of the user making theis request, if the user has been authenticated, or null if the user has not
been authenticated. whether the user name is sent with each subsequent request depends on the browser and
type of authentication.
Same as the value of the CGI variable EMOTE_USER.
Returns:
a String specifying the login of the user making this request, or null if the user login is not known
⑧ public java.lang.String getRequestedSessionId()
클라이언트이 세션 ID를 얻어 온다.
Returns the sessionID specified by the client. This may not be the same as the ID of the current valid session for this
request. if the client did not specify a session ID, this method returns null.
Returns:
a String specifying the session ID, or null if the request did not specify a session ID
⑨ public java.lang.String getRequestURI()
URI 값을 얻어 온다.
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
The web container does not decode this String. For example:
First line of HTTP request returns value
POST/some/path.html HTTP/1.1 /some/path.html
GET http://foo.bar/a.html HTTP/1.0 /a.html
HEAD /xyz?a=b HTTP/1.1 /xyz
To reconstruct an URL with a scheme and host, use HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest)
Returns:
a String containing the part of the URL from the protocol name up to the query string
⑩ public HttpSession getSession()
현재 세션을 리턴한다.
Returns the current session associated with this request, or if the reqeust does not have session, created one
Returns:
the HttpSession asscociated with this request
⑪ public HttpSession getSession(boolean create)
현재 세션(Session)을 리턴하거나, 없는 경우에 create 매개 변수의 값이 true이면 새로운 세션을 생성한다.
Returns the current HttpSession asscociated with this request or, if there is no current session and create is true,
returns a new session.
If create is false and the request has no valid HttpSession, this method returns null.
To make sure the session is properly maintained,you must call this method before the response is committed .
If the container is using cookies to maintain session integrity and is asked to create a new session when
the response is committed, an IllegalStateException is thrown
Parameters:
create - true to create new session for this request if necessaory; false to retrun null if there's no current session
Returns:
the HttpSession associated with this request or null if create is false and the request has no valid session
[Methods inherited from interface javax.servlet.ServletRequest]
① public java.lang.Object getAttribute(java.lang.String name)
주어진 이름을 이용해서 저장된 정보를 얻어 온다. 저장된 정보가 없으면 null 값을 리턴한다.
Returns the value of the named attribute as an Object, or null if no attribute of the given name exits;
Attribute can be set two ways. The servlet container may set attributes to make available custom information about a
request.
For example , for requests made using HTTPS, the attribute javax.servlet.request.X509Certificate can be used to
retrieve information on the certificate of the client. Attribute can also be set programtically using
setAttribute(java.lang.String, java.lang.Object).
This allows information to be embedded into a request before a RequestDispatcher call.
Attribute names should follow the same conventions as package names. This specification reserves names matching
java.*, javax.*, and sun.*.
Parameters:
name -a String specifying the name of the attribute
Returns
an Object containing the value of the attribute, or null if the attribute does not exit.
② public void removeAttribute(java.lang.String name)
주어진 이름의 정보를 삭제한다.
Removes an attribute from this request. This method is not generally needed as attributes only persist as long as
the request is being handled.
Attribute names should follow the same conventions as package names. Names beginning with java.*, javax.* and
com.sun.*, are reserved for use by Sun Microsystems.
Parameters:
name - a String specifying the name of the attribute to remove
③ public void setAttribute(java.lang.String name , java.lang.Object 0)
이름과 값의 형태로 정보를 저장한다.
Stores an attribute in this request. Attributes are reset between reqesuts. This method is most often used in
conjunction with RequestDispatcher.
Attribute names should follow the same conventions as package names . Names beginning with
java.*, javax.*, and com.sun.*, are reserved for use by Sun Microsystems.
if the object passed in is null, the effect is the same as calling removeAttribute(java.lang.String).
It is warned that when the request is dispatched from the servlet resides in a different web application
by RequestDispatcher, the object set by this method may not be correctly retrived in the caller servlet.
Parameters:
name -a String specifying the name of the attribute
a - the object to be stored
④ public RequstDispatcher getRequestDispatcher(java.lang.String path)
주어진 패스로 클라이언트의 요청을 전달한 RequestDispatcher를 얻어 온다.
Returns a RequestDispatcher obect that acts as a wrapper for the resource located ac the given path
A RequestDispatcher Object can be used to forward a request to the resource or to include the resource in a response.
The resource can be dynamic or static .
The pathname specified may be relative, although it canot extend outside the current servlet context.
If the path begins with a "/" it is interpreted as relative to the current context root. This method returns null
if the servlet container cannot return a RequestDispatcher.
The difference between this method and SErvletContext.getRequestDispacther(java.lang.String) is that this method can
take a relative path.
Parameters:
path - a String specifying the pathname to the resource. If it is relative , it must be relative aginst the current servlet.
returns:
a RequestDispatcher Object that acts as a wrapper for the resource at the specified path, or null if the servlet
container cannot return a RequestDispatcher
[클라이언트의 요청에 포함되어 있는 정보를 추출할 수 있는 메소드들]
⑤ public java.lang.String getParameter(java.lang.String name)
클라이언트의 요청에 포함되어 있는 주어진 일므의 파라미터 값을 리턴한다. 값이 없는 경우에 null을 리턴한다.
Returns the value of a request paramter as a String , or null if the paramter does not exit.
Request parameters are extra information sent with teh request. For HTTP servlet, parameter are contained in the
query string or posted from data.
You should use this method when you are sure the paramter has only one value. If the parameter might have more
than one value, use getParameterValues(java.lnag.String).
If you use this method with a multivalued paramter, the value returned is equal to the first value in the array returned by
getParameterValues.
If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body
directly via getInutStream() or getReader() cant interfere with the execution of this method.
Parameters:
name -a String specifying the name of the paramter
Returns
a String representing the single value of the paramter
⑥ public java.util.Enumeration getParameterNames()
클라이언트의 요청에 포함되어 있는 모든 파라미터 이름을 리턴한다.
Returns an Enumeration of String objects ocontaining the names of the parameters contained in the request.
If the request has no parameters, the method returns an emtpy Enumeration.
Returns:
an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if
the request if the request has no parameters
⑦ public java.lang.String[] getParameterValues(java.lang.String name)
주어진 이름의 파라미터 값을 모두 리턴한다.동일한 이름ㅇ 여러 개의 값이 있는 경우에 사용된다.
Returns an array of String objects containing all of the values the given request parameter has,
or null if the parameter does not exit.
If the paramter has a single value, the arrray has a length of 1.
Parameters:
name - a String containing the name of the parameter whose value is requested
Returns:
an array of String object containing the parameter's values
⑧ public java.lang.String getCharacterEncoding()
문자 데이터의 인코딩을 리턴한다.
Returns the name of the character encoding used in the body of this request.
This method returns null if the request does not specify a character encoding
Returns:
a String containing the name of the character encoding, or null if the request does not specify a character encoding
⑨ public java.lang.String getRemoteAddr()
요청를 보내는 클라이언트의 IP 주소를 리턴한다.
Returns the Internet Protocol(IP) address of the client or last proxy that sent the reqeust. For HTTP servlets, same as
the value of the CGI variable REMOTE_ADDR.
Returns:
a String containing the IP address of the client that sent the request
⑩ public java.lang.String getRemoteHost()
요청을 보내는 클라이언트의 이름을 리턴한다.
Returnsthe fully qualified name of the client or the last proxy that sent the request.
If the engine cannot or chooses not to resolve the hostname(to improve performance), this method returns the
dotted-string from of the IP address. For HTTP servlets, same as the value of the CGI variable REMOTE_HOST.
Returns:
a String conatining the fully qualified name of the client
⑵ HttpServletRequest를 이용한 헤더 값을 얻기 위한 메소드
① public java.lang.String getHeader(java.lang.String name)
파라미터에 해당하는 이름의 헤더 값을 리턴한다.
대소문자를 구별하지 않으며, 주어진 이름의 헤더 값이 없는 경우에 null 값을 리턴한다.
HTTP 헤더 정보를 찾아볼 때 매우 유용함.
Returns the value of the specified request header as a String. If the request did not include a header of the
specified name, this method returns null, If there are multipel headers with the samme name, this method returns the
first head in the request .
The header name is case insensitive. You can use this method with any request header.
Parameter:
name - a String specifying the header name
Returns:
a String containing the value of the requested header, or null if the request does not have a header of that name
② public java.util.Enumeration getHeaderNames()
HTTP 요청의 모든 헤더 이름을 Enumeration 타입으로 리턴한다. HTTP의 모든 헤더 정보를 파악하기 위해서 사용할 수
있다.
Returns an enumeration of all the header names this request contains. if the request has no headers, this method
returns an empty enumeration.
Some servlet containers do not allow servlets to access headers using this method, in which case this method
returns null
Returns:
an enumeration of all the header names sent with this request; if the request has no heders, an empty enumeration;
if the servlet container does not allow servlets to use this method, null
'기타 > 기타' 카테고리의 다른 글
공부할것들 (0) | 2016.04.20 |
---|---|
세션과 쿠키의 차이점 (0) | 2015.01.07 |
asd (0) | 2014.12.17 |
아키텍트의 종류와 역할 (0) | 2014.04.04 |
Jstl Customer Tag 사용법 (0) | 2013.02.01 |