• 주석문
    • <%-- --%>


JSP 페이지 구성요소

  • 디렉티브(Directive) - 지시자
    • page
      • JSP페이지에 대한 정보를 지정, JSP가 생성하는 문서의 타입. 출력 버퍼의 크기, 에러 페이지 등 JSP 페이지에서 필요로 하는 정보를 입력한다
      • <%@ page language="java" contentType="text/html; charset=UTF-8"%>
        • %@는 JSP에서 지시자(directive)라 한다. 
        • language="java"는  JSP에서 자바문법을 따라간다는 뜻.
        • contentType="text/html;charset=UTF-8"는 웹 상에 출력되는 언어 인코딩타입을 설정
    • taglib
      • JSP페이지에서 사용할 태그 라이브러리를 지정한다
      • <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
        • JSTL(커스텀태그) 태그 라이브러리 부분이다. 
        • JSTL태그는 톰캣에서 자체적으로 지원해 주지 않기 때문에 외부 라이브러리가 필요하다.
        • jakarta.apache.org사이트에서 jstl.jar,standard.jar 라이브러리를 다운받아서 JSTL 커스텀 태그 문법을 사용한다.
        • JSTL은 스프링 MVC 뷰페이지 문법으로 실전에서 사용하기 때문에 상당히 중요함.
          <c:if test="${!empty glist}"> <%-- JSTL c:if문, glist키값이 있는 경우 실행 --%>
              <c:forEach var="g" items="${glist}"> <%--JSTL FOR반복문 --%>
                  <
          tr>
                      <th
          >${g.g_no}</th> <%-- ${} 표현언어 즉 EL문법이다. JSTL은 아님. --%>
    • include
      • JSP페이지의 특정 영역에 다른 문서를 포함시킨다
      • <%@ include file="../include/header.jsp"%>

  • 스크립트(Script)
    • 선언부(Declaration)
      • 선언문은 변수정의,메서드 정의 를 할때 사용
        <%!
            private String result = "선언문";
            private String getStr() {
                
        result += "테스트입니다.";
                return result;
            }
        %>
    • 스크립트릿(Scriptlet)
      • 자바 코드를 실행한다
        <% String[] phone = { "010", "011", "016", "018", "019" }; %>
    • 표현식(Expression)

      • 값을 출력한다
        <%= phone[i] %>

  • 내장객체

    • request객체

      • 사용자 입력폼에서 입력한 자료를 서버로 가져오는 객체

    • response객체

      • 서버의 정보를 사용자 웹브라우저에 응답할때 사용한다.

      • sendRedirect("url") : 다른 웹 페이지로 이동

    • session객체

      • HTTP 세션 정보를 저장한다

  • 액션태그(Action Tag)

    • <jsp:include page="xxx.jsp"/> // 다른 페이지를 현재 페이지에 포함시킨다

    • <jsp:useBean id="use" class="model.UseBean" />
      JSP 유즈빈 액션태그로서 model패키지의 UseBean클래스의 새로운 객체명 use를 만듦. 
      자바 코드로 표현하면 
      model.UseBean use=new model.UseBean();

    • <jsp:setProperty name="use" property="*" />

    • useBean으로 선언된 UseBean클래스의 메서드를 호출한다

      프로퍼티 속성값을 *로 처리할수 있는 이유는 피라미터이름과 변수명이 같기 때문

    • <jsp:getProperty name="use" property="title" />

       UseBean클래스의 title변수에 저장된 제목값을 가져오는 jsp 유즈빈액션 태그


'Web Develop. > JSP' 카테고리의 다른 글

JSP 페이지 구성요소  (0) 2014.10.12
Include Directive  (0) 2014.09.30
<jsp:include>  (0) 2014.09.30
EL(Expression Language)  (0) 2014.09.23
jsp
http://www-it.fmi.uni-sofia.bg/courses/WDB/references/JSP%20syntax/syntaxref07.html

Include Directive

Includes a static file in a JSP file, parsing the file's JSP elements.

Syntax

<%@ include file="relativeURL" %>

Examples

include.jsp:
<html>
<head><title>An Include Test</title></head>
<body bgcolor="white">
<font color="blue">
The current date and time are
<%@ include file="date.jsp" %>
</font>
</body>
</html> date.jsp: <%@ page import="java.util.*" %>
<%= (new java.util.Date() ).toLocaleString() %> Displays in the page: The current date and time are
Aug 30, 1999 2:38:40

Description

The <%@ include %> directive inserts a file of text or code in a JSP file at translation time, when the JSP file is compiled. When you use the <%@ include %> directive, the include process is static. A static include means that the text of the included file is added to the JSP file. The included file can be a JSP file, HTML file, or text file. If the included file is a JSP file, its JSP elements are translated and included (along with any other text) in the JSP file. Once the included file is translated and included, the translation process resumes with the next line of the including JSP file.

The included file can be an HTML file, a JSP file, a text file, or a code file written in the Java programming language. Be careful that the included file does not contain <html></html><body>, or </body> tags. Because the entire content of the included file is added to the including JSP file, these tags would conflict with the same tags in the including JSP file, causing an error.

Some of the behaviors of the <%@ include %> directive depend on the particular JSP container you are using, for example:

  • The included file might be open and available to all requests, or it might have security restrictions.
  • The JSP page might be recompiled if the included file changes.

Attributes

  • file="relativeURL"

    The pathname to the included file, which is always a relative URL. Simply put, a relative URL is just the path segment of an URL, without a protocol, port, or domain name, like this:

    "error.jsp"
    "/templates/onlinestore.html"
    "/beans/calendar.jsp"

    If the relative URL starts with /, the path is relative to the JSP application's context, which is a javax.servlet.ServletContext object that is in turn stored in the application object. If the relative URL starts with a directory or file name, the path is relative to the JSP file.

Tip

  • If you are including a text file and do not want the text to be displayed in the JSP page, place the text in a comment element.


'Web Develop. > JSP' 카테고리의 다른 글

JSP 페이지 구성요소  (0) 2014.10.12
Include Directive  (0) 2014.09.30
<jsp:include>  (0) 2014.09.30
EL(Expression Language)  (0) 2014.09.23
jsp
http://www-it.fmi.uni-sofia.bg/courses/WDB/references/JSP%20syntax/syntaxref03.html

<jsp:include>

Includes a static file or sends a request to a dynamic file.

Syntax

<jsp:include page="{relativeURL | <%= expression %>}" flush="true" />
or
<jsp:include page="{relativeURL | <%= expression %>}" flush="true" >
<jsp:param name="parameterName"
value="{parameterValue | <%= expression %>}" />+
</jsp:include>

Examples

<jsp:include page="scripts/login.jsp" />
<jsp:include page="copyright.html" />
<jsp:include page="/index.html" /> <jsp:include page="scripts/login.jsp">
<jsp:param name="username" value="jsmith" />
</jsp:include>

Description

The <jsp:include> element allows you to include either a static or dynamic file in a JSP file. The results of including static and dynamic files are quite different. If the file is static, its content is included in the calling JSP file. If the file is dynamic, it acts on a request and sends back a result that is included in the JSP page. When the include action is finished, the JSP container continues processing the remainder of the JSP file.

You cannot always determine from a pathname if a file is static or dynamic. For example, http://server:8080/index.html might map to a dynamic servlet through a Web server alias. The <jsp:include>element handles both types of files, so it is convenient to use when you don't know whether the file is static or dynamic.

If the included file is dynamic, you can use a <jsp:param> clause to pass the name and value of a parameter to the dynamic file. As an example, you could pass the string username and a user's name to a login form that is coded in a JSP file.

Attributes

  • page="{relativeURL | <%= expression %>}"

    The relative URL that locates the file to be included, or an expression that evaluates to a String equivalent to the relative URL.

    The relative URL looks like a pathname-it cannot contain a protocol name, port number, or domain name. The URL can be absolute or relative to the current JSP file. If it is absolute (beginning with a /), the pathname is resolved by your Web or application server.

  • flush="true"

    You must include flush="true", as it is not a default value. You cannot use a value of false. Use the flush attribute exactly as it is given here.

  • <jsp:param name="parameterName" 
    value="{parameterValue | <%= expression %>}" />+

    The <jsp:param> clause allows you to pass one or more name/value pairs as parameters to an included file. The included file should be dynamic, that is, a JSP file, servlet, or other file that can process the parameter.

    You can use more than one <jsp:param> clause if you want to send more than one parameter to the included file. The name attribute specifies the parameter name and takes a case-sensitive literal string. The value attribute specifies the parameter value and takes either a case-sensitive literal string or an expression that is evaluated at request time.


'Web Develop. > JSP' 카테고리의 다른 글

JSP 페이지 구성요소  (0) 2014.10.12
Include Directive  (0) 2014.09.30
<jsp:include>  (0) 2014.09.30
EL(Expression Language)  (0) 2014.09.23

+ Recent posts