Java's JSP basic syntax

Source: Internet
Author: User
Tags html comment

1.JSP page Element Introduction and page directive 2.JSP Comment, 3 different annotations<!--I'm an HTML comment, visible on the client--<%--I am a JSP comment that is not visible on the client--%>
<% //I am a script line comment / * I'm a script multiline comment script Comment not visible on client * / %>
3.JSP script for writing scripts, syntax: <%%><%Out.print ("Welcome you to learn Java EE course"); %>
4.JSP Declaration,used to declare Java variables or partieslaw, Syntax: <%! variable or method%><%!    String s="China"; int Add (int x,int y)        { return x+y;         } %>
5.JSP expression, an expression executed in a JSP page (invoking a declared variable or function), syntax: <%= expression%>//Note expression does not end with good points      Hello,<%=s%>5+10=<%=Add (5,10) %>
6.JSP page life cycle 7. Related Exercises
12345678910111213141516171819202122232425262728293031323334353637383940 <%@page import="org.apache.jasper.tagplugins.jstl.core.Out"%><%@ 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"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>九九乘法表</title></head><body>    <h1>九九乘法表</h1>    <hr>    <%!        //通过表达式来实现        String printMultiTable1(){            String s="";            for(int i=1;i<=9;i++){                for(int j=1;j<=i;j++){                    s+=j+"*"+i+"="+(i*j)+"&nbsp;&nbsp;&nbsp;&nbsp;";                }                s+="<br>";            }            return s;        }        //使用脚本来实现        void printMultiTable2(JspWriter out)throws Exception{            for(int i=1;i<=9;i++){                for(int j=1;j<=i;j++){                    out.println(j+"*"+i+"="+(i*j)+"&nbsp;&nbsp;&nbsp;&nbsp;");                }                out.println("<br>");            }        }    %>        <%=printMultiTable1() %>    <hr>    <% printMultiTable2(out); %></body></html>



From for notes (Wiz)

Java's JSP basic syntax

Related Article

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.