JSP basic syntax

Source: Internet
Author: User

JSP directives:

page, usually at the top of the JSP page, can have multiple page directives on the same page

Include, embed an external file into the current JSP file, and parse the JSP statements in this page

Taglib, using the tag library to define a new custom label, start the custom behavior in the JSP page

Page instruction Syntax:

<% @page Property 1 = "" Property 2= "" ...%>

Property:

Language, specifying the scripting language used by JSP pages, default Java

Import, which refers to the class file used in the scripting language, with no default value

ContentType, used to specify the encoding method used by the JSP page, the default value cannot be parsed in Chinese, generally write contenttype= "text/html; Charset=utf-8"

JSP comments:

Comments in HTML:<!--HTML annotations-->//client visible

Comments in JSP: <%--jsp comment--%>//Client not visible

JSP script Comment: <%//or/**/%>//single row, multiple lines, not visible

JSP declaration:

Defining variables or methods in a JSP page

Syntax: <%! Java Code%>

<%!     String s= "xiaoming";     int Add (int x,int  y)    {        return x+y;    } %>
JSP expression:

Expressions that are executed in a JSP page

Syntax: <%= expression%>//Note that the expression does not end with a semicolon!

Hello, <%=s%><br>1+1=<%=add (10,5)%>

<%= variable%> is a shorthand for <% out.println (variable)%>
Display the date on the page:

First you need to import, date package

<% @page import= "Java.util.Date"%>

Then you need to get the current date:

<%    simpledateformat nowdate=new simpledateformat ("yyyy year mm DD Day");    String s=nowdate.format (new  Date ()); %> today is:<%=s%>

JSP basic syntax

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.