JSP Componets Quick summary

JSP Syntax:

1. Declarations

A declaration declares one or more variables or methods that you can use in Java code later in the JSP file. (Don’t really see only use declarations, usually declare in the scriptlet.

<%! declaration; [ declaration; ]+ ... %>
<jsp:declaration>
   //code fragment
</jsp:declaration>

<%! int i = 0; %> 
<%! int a, b, c; %> 
<%! Circle a = new Circle(2.0); %> 
2. Scriptlet

A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.

<% code fragment %> //or
<jsp:scriptlet>
   code fragment
</jsp:scriptlet>
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
3. Expression

The expression element can contain any expression that is valid according to the Java Language Specification but you cannot use a semicolon to end an expression.

<jsp:expression>
   expression
</jsp:expression>

<html> 
<head><title>A Comment Test</title></head> 
<body>
<p>
   Today's date: <%= (new java.util.Date()).toLocaleString()%>
</p>
</body> 
</html> 
Comment:
</%comment%/>
<%--comment--%>
Directives

A JSP directive affects the overall structure of the servlet class. It usually has the following form:

<%@ page ... %> Defines page-dependent attributes, such as scripting language, error page, and buffering requirements.
<%@ include ... %>  Includes a file during the translation phase.
<%@ taglib ... %>   Declares a tag library, containing custom actions, used in the page
Actions
<jsp:action_name attribute="value" />

这里写图片描述

JSP implicit objects

request, response, out, session, application, config, pageContext, page, Exception.

Interesting! jsp flow control with html

The if…else block starts out like an ordinary Scriptlet, but the Scriptlet is closed at each line with HTML text included between Scriptlet tags.

<%! int day = 3; %>
<% if (day == 1 | day == 7) { %>
    <p> Today is weekend</p>
<% } else { %>
    <p> Today is not weekend</p>
<% } %>

For loop:
“`
<%
for ( fontSize = 1; fontSize <= 3; fontSize++){ %>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值