본문 바로가기

JAVA/JSP & Servlet

JSP 기본 실습 : out, application 내장변수

1. out

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8" autoFlush="false" %>

 

<%

        //out 객체 [flush, clearBuffer, close]

       

        out.println("1<br/>");

        out.println("2<br/>");

        out.println("3<br/>");

        out.flush();

        out.println("4<br/>");

        out.println("5<br/>");

        out.println("6<br/>");

        //버퍼에서 제거

        out.clearBuffer();

        out.println("7<br/>");

        out.println("8<br/>");

        out.println("9<br/>");

        out.flush();

        out.println("10<br/>");

        out.println("11<br/>");

        out.println("12<br/>");

        //출력버퍼를 close

        out.close();

        out.println("13<br/>");

       

        /*

         */

%>

 

 

 

 

 

 

 

 

 

 

 

 


 

2. application

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>JSP : application</title>

</head>

<body>

<%

        String info = application.getServerInfo();

        int major = application.getMajorVersion();

        int minor = application.getMinorVersion();

        //서블릿 클래스 파일이 있는 위치

        String path1 = application.getRealPath("/");

        //실행되고 있는 디렉토리만 표시

        String path2 = application.getContextPath();

       

        out.println("info : " + info + "<br />");

        out.println("major : " + major + "<br />");

        out.println("minor : " + minor + "<br />");

        out.println("path1 : " + path1 + "<br />");

        out.println("path2 : " + path2 + "<br />");

%>

 

</body>

</html>