일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- unity #animation #animator #mixamo #character
- Android #AndroidStudio #안드로이드스튜디오 #안드로이드스튜디오설치 #안드로이드앱개발
- 전시진강의후기
- Unity
- unity #mixamo #character #texture #material
- 시리얼강의후기
- 시리얼노션
- 게임개발
- Today
- Total
HB의 개발 블로그
[Web] 12. JSP 본문
JSP Directive Elements
Directives란, web 에서 JSP를 어떻게 servlet으로 변경 할 수 있는지 알려 줄때 사용하는 명령어의 한 종류이다.
Directives에는 세 가지 타입이 존재한다.
- Page directive : The page directive defines attributes that apply to an entire JSP page.
- include directive
- taglib directive
JSP page directive Syntax
<%@ directive attribute="value"%>
Attributes of JSP page directive
- import: JSP에서 사용할 패키지나 Class들을 import 할 때에 사용한다.
<html>
<body>
<%@ page import="java.util.Date" %>
Today is: <%= new Date() %>
</body>
</html>
- contentType: JSP가 생성할 문서의 type을 정한다.
<html>
<body>
<%@ page contentType=application/msword %>
Today is: <%= new java.util.Date() %>
</body>
</html>
- extends: 상속받을 부모 클래스를 정의한다.
- info: JSP에 대한 설명을 입력하는데에 사용한다.
<html>
<body>
<%@ page info="composed by Sonoo Jaiswal" %>
Today is: <%= new java.util.Date() %>
</body>
</html>
- buffer: 페이지에서 생성 된 출력 버퍼 크기를 설정한다. (기본 크기 :8kb)
<html>
<body>
<%@ page buffer="16kb" %>
Today is: <%= new java.util.Date() %>
</body>
</html>
- language: 스크립트 언어를 지정한다.
- isELIgnored: JSP의 Expression Language를 무시할때에 사용한다.
<%@ page isELIgnored="true" %>//Now EL will be ignored
- isThreadSafe: 동시에 여러 브라우저의 요청에 대해서 처리 여부를 설정한다.
public class SimplePage_jsp extends HttpJspBase
implements SingleThreadModel{
.......
}
- errorPage: 오류가 발생했을 때 오류페이지로 이동하도록 사용.
//index.jsp
<html>
<body>
<%@ page errorPage="myerrorpage.jsp" %>
<%= 100/0 %>
</body>
</html>
- isErrorPage: 현재 JSP페이지가 error page인지 아닌지 여부를 지정할때에 사용한다.
//myerrorpage.jsp
<html>
<body>
<%@ page isErrorPage="true" %>
Sorry an exception occured!<br/>
The exception is: <%= exception %>
</body>
</html>
JSP include directive
파일을 JSP 페이지 내에 포함시킬 때에 사용한다. 코드의 Reusability가 향상된다.
Syntax of the include directive
<%@ include file="resourceName" %>
Example
<html>
<body>
<%@ include file="header.html" %>
Today is: <%= java.util.Calendar.getInstance().getTime() %>
</body>
</html>
JSP taglib directive
JSP페이지에서 사용자 정의 태그를 정의할 때에 사용.
Syntax of the Taglib directive
<%@ taglib uri="uriofthetaglibrary" prefix="prefixoftaglibrary" %>
Example
<html>
<body>
<%@ taglib uri="http://www.javatpoint.com/tags" prefix="mytag" %>
<mytag:currentDate/>
</body>
</html>
JSP Action Elements
페이지들 간의 플로우를 제어하고 Java Bean을 이용하는데에 사용이 된다.
JSP Action Tags | Description |
jsp:forward | forwards the request and response to another resource. |
jsp:include | includes another resource. |
jsp:useBean | creates or locates bean object. |
jsp:setProperty | sets the value of property in bean object. |
jsp:getProperty | prints the value of property of the bean. |
jsp:plugin | embeds another components such as applet. |
jsp:param | sets the parameter value. It is used in forward and include mostly. |
jsp:fallback | can be used to print the message if plugin is working. It is used in jsp:plugin. |
jsp:forward action tag
받은 요쳥을 다른 resources로 전달하는데에 사용된다.
Syntax of jsp:forward action tag without parameter
<jsp:forward page="relativeURL | <%= expression %>" />
Syntax of jsp:forward action tag with parameter
<jsp:forward page="relativeURL | <%= expression %>">
<jsp:param name="parametername" value="parametervalue | <%=expression%>" />
</jsp:forward>
jsp:include action tag
코드를 재사용할 수 있어 시간을 절약할 수 있도록 한다.
Syntax of jsp:include action tag without parameter
<jsp:include page="relativeURL | <%= expression %>" />
Syntax of jsp:include action tag with parameter
<jsp:include page="relativeURL | <%= expression %>">
<jsp:param name="parametername" value="parametervalue | <%=expression%>" />
</jsp:include>
JavaBean
JavaBean은 재사용 가능한 소프트웨어의 구성 요소이다. 여러 가지의 개체들을 하나의 객체로 캡슐화 함으로써 접근성이 향상되어 유지 보수에 용이하다.
Conventions
- 인수 없는 생성자가 존재해야한다.
- 직력화가 되어야한다.
- getter, setter 와 같은 메소드를 제공해야 한다.
Properties
- getPropertyName() : property 이름이 firstname인 경우, 메소드 이름은 getFirstName() 으로 읽는다.
- setPropertyName() : property 이름이 firstname인 경우, 메소드 이름은 setFirstName() 으로 읽는다.
Advantages
- JavaBean의 속성이나 메소드는 다른 프로그램에서도 접근이 가능하다.
- 소프트웨어 구성요소들을 쉽게 재사용할 수 있다.
jsp:useBean action tag
Bean 클래스를 찾거나 인스턴스화하는데에 사용된다.
Syntax of jsp:useBean action tag
<jsp:useBean id= "instanceName" scope= "page | request | session | application"
class= "packageName.className" type= "packageName.className"
beanName="packageName.className | <%= expression >" >
</jsp:useBean>
Attributes | Usage |
id | identify the bean in the specified scope |
scope | represents the scope of the bean. It may be page, request, session or application. The default scope is page. |
class | instantiates the specified bean class (i.e. creates an object of the bean class) but it must have no-arg or no constructor and must not be abstract. |
type | provides the bean a data type if the bean already exists in the scope. It is mainly used with class or beanName attribute. If you use it without class or beanName, no bean is instantiated. |
beanName | instantiates the bean using the java.beans.Beans.instantiate() method. |
Simple Example
Calculator.java
package com.javatpoint;
public class Calculator{
public int cube(int n){return n*n*n;}
}
index.jsp file
<jsp:useBean id="obj" class="com.javatpoint.Calculator"/>
<%
int m=obj.cube(5);
out.print("cube of 5 is "+m);
%>
setProperty and getProperty action tags
setProperty 및 getProperty 작업 태그는 Java Bean으로 웹 응용 프로그램을 개발하는 데 사용된다.
Syntax of jsp:setProperty action tag
<jsp:setProperty name="instanceOfBean" property= "*" |
property="propertyName" param="parameterName" |
property="propertyName" value="{ string | <%= expression %>}"
/>
Syntax of jsp:getProperty action tag
<jsp:getProperty name="instanceOfBean" property="propertyName" />
JSP Expression Language
EL은 Java Bean 컴포넌트에 저장된 데이터 및 요청, 세션, 애플리케이션 등의 기타 객체의 접근성을 단순화한다.
Syntax for Expression Language (EL)
${ expression }
Implicit Objects | Usage |
pageScope | it maps the given attribute name with the value set in the page scope |
requestScope | it maps the given attribute name with the value set in the request scope |
sessionScope | it maps the given attribute name with the value set in the session scope |
applicationScope | it maps the given attribute name with the value set in the application scope |
param | it maps the request parameter to the single value |
paramValues | it maps the request parameter to an array of values |
header | it maps the request header name to the single value |
headerValues | it maps the request header name to an array of values |
cookie | it maps the given cookie name to the cookie value |
initParam | it maps the initialization parameter |
pageContext | it provides access to many objects request, session etc. |
'Web' 카테고리의 다른 글
[Web] 13. Spring (0) | 2020.08.10 |
---|---|
[Web] 11. JSP 개발환경설정 (0) | 2020.08.07 |
[Web] 10. jQuery (0) | 2020.07.30 |
[Web] 09.JavaScript (Forms~Nodes) (0) | 2020.07.29 |
[Web] 08.JavaScript (Functions~JSON) (0) | 2020.07.28 |