W3schools - JSP_Elements
찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요
Elements
Scriptlet
Can contain any number of JAVA lang statements, variable or method declarations, or expressing that are valid in the page scripting lang
<!-- Syntax -->
<% code fragment %>
<!-- Can write the XML equivalent -->
<jsp:scriptlet>
code fragment
</jsp:scriptlet>
<!--- Any text, HTML or JSP elements you write must be outside the scriptlet -->
<body>
Hello World!<br>
<%
out.println(“Id address = ” + request.getRemoteAddr());
%>
</body>
Declaration
It declares one or more variables or methods that you can use in Java code later in the JSP file
- Must declare the variable or method before use it
<!-- Syntax -->
<%! Declaration; [ declaration; ] + … %>
<% Can write the XML equivalent %>
<jsp:declaration>
Code fragment
</jsp:declaration>
<!-- in jsp -->
<%! int i = 0;%>
<%! int a, b, c; %>
<%! Circle a = new Circle(2.0); %>
Expression
JSP expression element contains a scripting lang expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file
The expression element can contain any expression that is valid according to the Java lang Specification but you can’t use a semicolon to end an expression
<!-- Syntax -->
<%= expression %>
<!-- Can write the XML equivalent -->
<jsp:expression>
expression
</jsp:expression>
<!-- in jsp -->
<p> date : <%= (new java.util.Date()).toLocalString() %></p>
Comment
<%-- This is JSP comment --%>
Directive
Directive affects the overall structure of the servlet class
<%@ directive attribute= “value” %>
<%@ page …. %>
<!-- Defines page-dependent attributes(scripting lang, error page, buffering requirements…) -->
<%@ include …. %>
<!-- includes a file during the translation phase -->
<%@ taglib …. %>
<!--- Declares a tag library, containing custom actions, used in the page -->
Action
It uses constructs in XML syntax to control the behavior of the servlet engine
<jsp:action_name attribute=“value”>
Action elements are basically predefined functions
Syntax | Purpose |
---|---|
jsp:include | Include a file at the time the page is requested |
jsp:useBean | Finds or instantiates a JavaBean |
jsp:setProperty | Sets the property of a JavaBean |
jsp:getProperty | Inserts the property of a JavaBean into the output |
jsp:forward | Forwards the requester to a new page |
jsp:plugin | Generates browser-specific code that makes an OBJECT or EMBED tag for the Java plugin |
jsp:element | Defines XML elements dynamically |
jsp:attribute | Defines dynamically-defined XML element’s attribute |
jsp:body | Defines dynamically-defined XML element’s body |
jsp:text | Used to write template text in JSP pages and documents |
Implicit Object
JSP supports nine automatically defined variables, which are also called implicit
Object | Description |
---|---|
request | Is the HttpServletRequest object associated with the request |
response | Is the HttpServletResponse object associated with the response to the client |
out | Is the PrintWriter object used to send output to the client |
session | Is the HttpSession object associated with the request |
application | Is the ServletContext object associated with the application context |
config | Is the ServletConfig object associated with the page |
pageContext | Encapsulates use of server-specific features like higher performance JspWriters |
page | This is simply a synonym for this, and is used to call the methods defined by the translated servlet class |
Exception | It is allows the exception data to be accessed by designated JSP |
Control-Flow
Can use all the APIs and building blocks of Java in JSP programming including decision-making statements, loops