Basic syntax for JSP JSP

Source: Internet
Author: User

JSP template elements
?jsp页面中的HTML 内容称为JSP模板元素?jsp模板元素定义了网页的基本骨架,即定义了页面结构和外观
JSP expressions
? jsp脚本表达式用于将程序数据输出到客户端? 语法<%=变量 或者表达式%>? 例如输出当前时间:<%= new java.util.Date()%>? jsp引擎在翻译脚本表达式的时候,会将程序数据转换成字符串,然后在相应的位置用out.print(...)将数据输出给客户端?ps:jsp脚本表达式的变量和表达式后面不能有分号";"<body> ? ?<% int i=0; %> ? ?<p>输出jsp中定义的变量i=<%=i %></p></body> ?
JSP script Fragment
? jsp脚本片段用于在JSP页面中编写多行java代码。语法:? <%多行java代码%> 在<%%>可以定义变量编写语句,不能定义方法<% ?//声明变量 ?int sum=0; ?for(int i=0;i<100;i++){ ? ? sum+=i; ? } ?out.println("
JSP declaration
? jsp页面中编写的所有的代码,默认会翻译到servlet的service()方法中,而jsp声明中的java代码被翻译到_jspService方法的外面。<%!java代码%>所以jsp声明可以用于定义jsp页面转换成的servlet程序的静态代码块,成员变量和方法。多个静态代码块,变量和函数可以定义在jsp声明中,也可以分别单独定义在多个jsp声明中。jsp隐式对象的作用范围仅限于servlet的_jspService方法,所在jsp声明中不能使用这些隐式对象。
Comments for JSP
显式注释:直接使用HTML风格的注释<!--注释内容-->隐式注释:直接使用java的注释// /*....*/JSP自己的注释: <%--注释的内容--%><%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Basic syntax for JSP JSP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.