::: Zany's Homepage ::: Zany Wiki | »çÀÌÆ® ÅëÇÕ °Ë»ö
 
 
 

JSP ³»Àå °´Ã¼ ¹× ±âº» »ç¿ë¹ý

°Ô½ÃÆÇ
Jsp, Applet, Servlet
ÀÛ¼ºÀÚ
helix
ÀÛ¼ºÀÏ
2009-05-07 20:55:24
ÀÐÀº¼ö
3267
ÆòÁ¡
   
Ç¥½Ã¿É¼Ç
HTML»ç¿ë | ÀÚµ¿BRűנ| °ø¹é¹®ÀÚÇã¿ë | °¡¿îµ¥Á¤·Ä | °íÁ¤Æø±Û²Ã | ÀÚµ¿URL¸µÅ© | ¸¶¿ì½º¼±ÅÃ
¡á localÀÇ ±âº» Á¤º¸ (IP, Name, Port)
    Local IP : <%=request.getLocalAddr()%>
    Local Name : <%=request.getLocalName()%>
    Local Port : <%=request.getLocalPort()%>

¡á Ŭ¶óÀ̾ðÆ®ÀÇ Á¤º¸
    Remote IP : <%=request.getRemoteAddr()%>
    Remote Host : <%=request.getRemoteHost()%>
    Remote Port : <%=request.getRemotePort()%>

¡á ¼­¹ö À̸§°ú Æ÷Æ® (ÀϹÝÀûÀ¸·Î local ±âº»Á¤º¸¿Í µ¿ÀÏ)
    Server Name : <%=request.getServerName()%>
    Server Port : <%=request.getServerPort()%>

¡á Áö¿ª Á¤º¸ (´ëºÎºÐ Çѱ¹À» ÀǹÌÇÏ´Â ko°¡ ³ª¿È)
    Locale : <%=request.getLocale()%>

¡á »ç¿ëÇÏ´Â ÇÁ·ÎÅäÄÝ ("ÇÁ·ÎÅäÄÝ/¸ÞÀÌÀú¹öÀü.¸¶À̳ʹöÀü" ÀÇ ÇüÅÂ)
    Protocol : <%=request.getProtocol()%>

¡á http, https, ftp¿Í °°Àº °ÍÀ» ÀǹÌ
    Scheme : <%=request.getScheme()%>

¡á https¿Í °°Àº º¸¾È ä³ÎÀÇ »ç¿ë ¿©ºÎ (true/false °ªÀ¸·Î µÇ¾î ÀÖÀ½)
    Secure Channel : <%=request.isSecure()%><br>

¡á ¿äû¿¡ ´ëÇÑ URI, URL, ÄÁÅؽºÆ® °æ·Î, ¼­ºí¸´ °æ·Î, GET/POSTµîÀÇ ¸Þ¼Òµå
    Request's URI : <%=request.getRequestURI()%>
    Request's URL : <%=request.getRequestURL()%>
    Context Path : <%=request.getContextPath()%>
    Servlet Path : <%=request.getServletPath()%>
    Method : <%=request.getMethod()%>

¡á ¼¼¼Ç ID¿¡ ´ëÇÑ Á¤º¸
    Session ID : <%=request.getRequestedSessionId()%>
    Session ID from Cookie : <%=request.isRequestedSessionIdFromCookie()%>
    Session ID from URL : <%=request.isRequestedSessionIdFromURL()%>
    Session ID is still valid : <%=request.isRequestedSessionIdValid()%>

¡á Header Á¤º¸
    <%
        Enumeration eHeader = request.getHeaderNames();
        while (eHeader.hasMoreElements()) {
            String hName = (String)eHeader.nextElement();
            String hValue = request.getHeader(hName);
            out.println(hName + " : " + hValue + "<br>");
        }
    %>

¡á Request °´Ã¼¸¦ ÅëÇؼ­ ÄíÅ° Á¤º¸¸¦ º¸´Â ¹æ½Ä
    <%
        Cookie cookies[] = request.getCookies();
        for (int i=0; i < cookies.length; i++) {
            String name = cookies[i].getName();
            String value = cookies[i].getValue();
            out.println(name + " : " + value + "<br>");
        }
    %>

    /**
    * cookie °ªÀ» ¼³Á¤ÇÏ´Â ¸Þ¼Òµå.
    * @param HttpServletResponse response
    * @param String cookieName
    * @param String cookieValue
    */
    public void setCookie(HttpServletResponse response, String cookieName, String cookieValue) {
        int maxAge = (60 * 60 * 24 * 15); // 15day
        setCookie(response, cookieName, cookieValue, maxAge);
    }

    /**
    * cookie °ªÀ» ¼³Á¤ÇÏ´Â ¸Þ¼Òµå.
    * @param HttpServletResponse response
    * @param String cookieName
    * @param String cookieValue
    * @param int maxAge
    */
    public void setCookie(HttpServletResponse response, String cookieName, String cookieValue, int maxAge) {
        cookieValue = URLEncoder.encode(cookieValue);
        Cookie cookie = new Cookie(cookieName, cookieValue);
        cookie.setMaxAge(maxAge);
        response.addCookie(cookie);
    }

    /**
    * cookie °ªÀ» ã¾Æ¼­ ¸®ÅÏÇÏ´Â ¸Þ¼Òµå.
    * @param HttpServletRequest request
    * @param String cookieName
    * @return String
    */
    public String getCookie(HttpServletRequest request, String cookieName) {
        Cookie[] cookies = request.getCookies();
        String cookieValue = null;
        for (int i = 0; i < cookies.length; i++) {
            if (cookieName.equals(cookies[i].getName())) {
                cookieValue = URLDecoder.decode(cookies[i].getValue());
                break;
            }
        }
        return cookieValue;
    }

¡á HTML ÆûÀ» ÅëÇØ ³Ñ¾î¿Â µ¥ÀÌÅ͸¦ ¹Þ´Â ºÎºÐ
    <%
        Enumeration eParam = request.getParameterNames();
        while (eParam.hasMoreElements()) {
            String pName = (String)eParam.nextElement();
            String pValue = request.getParameter(pName);

            out.println(pName + " : " + pValue + "<br>");
        }
    %>

¡á ¹Ì¸® ¼³Á¤ÇÑ attribute¸¦ °¡Á®¿À´Â ºÎºÐ
    <%
        Enumeration eAttr = request.getAttributeNames();
        while (eAttr.hasMoreElements()) {
            String aName = (String)eAttr.nextElement();
            String aValue = request.getHeader(aName);

            out.println(aName + " : " + aValue + "<br>");
        }
    %>


=============================================================
// Ŭ¶óÀ̾ðÆ® Á¤º¸ ¹× ¼­¹öÁ¤º¸ Àбâ
=============================================================
    String  getRemoteAddr()            À¥¼­¹ö¿¡ ¿¬°áÇÑ Å¬¶óÀ̾ðÆ®ÀÇ IP ÁÖ¼Ò¸¦ °¡Á®¿Â´Ù.
    long    getContentLength()         Ŭ¶óÀ̾ðÆ®°¡ Àü¼ÛÇÑ ¿äû Á¤º¸ÀÇ ±æÀ̸¦ ±¸Çؿ´Ù.
    String  getCharacterEncoding()     Ŭ¶óÀ̾ðÆ®°¡ ¿äû Á¤º¸¸¦ Àü¼ÛÇÒ ¶§ »ç¿ëÇÑ Ä³¸¯ÅÍÀÇ  ÀÎÄÚµùÀ» ±¸Çؿ´Ù.
    String  getContentType()           Ŭ¶óÀ̾ðÆ®°¡ ¿äû Á¤º¸¸¦ Àü¼ÛÇÒ ¶§ »ç¿ëÇÑ ÄÁÅÙÃ÷ÀÇ Å¸ÀÔÀ» ±¸Çؿ´Ù.
    String  getProtocol()              Å¬¶óÀ̾ðÆ®°¡ ¿äûÇÑ ÇÁ·ÎÅäÄÝÀ» ±¸ÇÑ´Ù.
    String  getMethod()                À¥ ºê¶ó¿ìÀú°¡ Á¤º¸¸¦ Àü¼ÛÇÒ ¶§ »ç¿ëÇÑ ¹æ½ÄÀ» ±¸ÇÑ´Ù.
    String  getRequestURI()            À¥ ºê¶ó¿ìÀú°¡ ¿äûÇÑ URL¿¡¼­ °æ·Î¸¦ ±¸ÇÑ´Ù.
    String  getContextPath()           JSPÆäÀÌÁö°¡ ¼ÓÇÑ À¥ ¾îÇø®ÄÉÀ̼ÇÀÇ ÄÜÅؽºÆ® °æ·Î¸¦±¸ÇÑ´Ù.
    String  getServerName()            ¿¬°áÇÒ ¶§ »ç¿ëÇÑ ¼­¹ö À̸§À» ±¸ÇÑ´Ù.
    String  getServerPort()            ¼­¹ö°¡ ½ÇÇà ÁßÀÎ Æ÷Æ® ¹øÈ£¸¦ ±¸ÇÑ´Ù.

=============================================================
// HTMLÆû°ú ¿äûÆĶó¹ÌÅÍ Ã³¸®
=============================================================
    String  getParameter(String name)              À̸§ÀÌ nameÀÎ ÆĶó¹ÌÅÍÀÇ °ªÀ» ±¸ÇÑ´Ù(Request("name") °ú µ¿ÀÏ)
    String[]  getParameterValues(String name)      À̸§ÀÌ nameÀÎ ¸ðµç ÆĶó¹ÌÅÍÀÇ °ªÀ» ¹è¿­·Î °¡Á®¿Â´Ù.
    java.util.Enumeration  getParameterNames()     À¥ºê¶ó¿ìÀú°¡ Àü¼ÛÇÑ ÆĶó¹ÌÅÍÀÇ À̸§À» ±¸ÇÑ´Ù.
    java.util.Map  getParameterMap()               À¥ºê¶ó¿ìÀú°¡ Àü¼ÛÇÑ ÆĶó¹ÌÅÍÀÇ ¸ÊÀ» ±¸ÇÑ´Ù.

    ex> nameÆĶ÷ = request.getParameter("name")
        Enumeration enum = request.getParameterNames();
            while(enum.hasMoreElements)
                String name = (String)enum.nextElement();

=============================================================
// ¿äû Çì´õ Á¤º¸ÀÇ Ã³¸®
=============================================================
    String  getHeader(String name)                 ÁöÁ¤ÇÑ À̸§ÀÇ Çì´õ°ªÀ» ±¸ÇÑ´Ù.
    java.util.Enumeration  getHeasers(String name) ÁöÁ¤ÇÑ À̸§ÀÇ Çì´õ ¸ñ·ÏÀ» ±¸ÇÑ´Ù.
    java.util.Enumeration  getHeaderName()         ¸ðµç Çì´õÀÇ À̸§À» ±¸ÇÑ´Ù.
    int  getIntHeader(String name)                 ÁöÁ¤ÇÑ Çì´õÀÇ °ªÀ» Á¤¼ö°ªÀ¸·Î Àоî¿Â´Ù.
    long getDateHeader(String name)                ÁöÁ¤ÇÑ Çì´õÀÇ °ªÀ» ½Ã°£°ªÀ¸·ÎÀоî¿Â´Ù (1970³â1¿ù1ÀÏ ÀÌÈÄ·Î Èê·¯°£ 1/1000ÃÊ ´ÜÀ§·Î Àоî¿Â´Ù)

    ex> Enumeration enum = request.getHeaderNames();
            while(enum.hasMoreElements()){
                String headerName = (String)enum.nextElement();
                String headerValue = request.getHeader(headerName);
            }

=============================================================
// °ª ¼³Á¤Çϱâ(Attribute)
=============================================================
    void  setAttribute(String name, Object values)   À̸§ÀÌ nameÀÎ ¼Ó¼ºÀÇ °ªÀ» values·Î ÀúÀåÇÑ´Ù.
    Object getAttribute(String name)                 À̸§ÀÌ nameÀÎ ¼Ó¼ºÀÇ °ªÀ» ±¸ÇÑ´Ù.
    void removeAttribute(String name)                À̸§ÀÌ nameÀÎ ¼Ó¼ºÀ» »èÁ¦ÇÑ´Ù.
    java.util.Enumeration getAttributeNames()        ¼Ó¼ºÀÇ À̸§ ¸ñ·ÏÀ» ±¸ÇÑ´Ù.

    ## ÁÖÀÇ : setAttribute ¿¡¼­ °ªÀÌ ObjectÀ̱⠶§¹®¿¡ int, double°ú °°Àº ±âº» µ¥ÀÌÅÍ Å¸ÀÔÀº
    ¼Ó¼º°ª¿¡ ÇÒ´ç ÇÒ ¼ö ¾ø´Ù. ÀÌÀ¯´Â Object°¡ ¾Æ´Ï±â ¶§¹®ÀÌ´Ù. ÀÌ °æ¿ì¿£ ·¹ÆÛ Å¬·¡½º¸¦ »ç¿ëÇØ¾ß ÇÑ´Ù.
        Integer intValue = new Integer(100);
        request.setAttribute("radio", intValue);
        ...
        Integer intValue = (Integer)request.getAttribute("radio");
        int value = intValue.intValue();

 °Ô½ÃÆÇ ±Û ¸ñ·Ï
No Subject Poster Hits Posted
2476 helix 6765 2010-08-02 20:19:02
2203
[0] Struts2
helix 3258 2009-10-26 12:33:59
2146 helix 3334 2009-09-08 11:02:51
helix 3267 2009-05-07 20:55:24
1898 helix 7657 2009-05-07 20:26:08
1887 helix 7020 2009-04-28 19:37:56
ÄÚ¸àÆ®
ÀÛ¼ºÀÚ
                       
 
zany.kr
  Copyright ¨Ï 2002-2010 Zany's Programming Lab. All Rights Not Reserved.
temporary This Page loads on 0.000 Secs