JSP basic syntax

Source: Internet
Author: User
Tags html comment

Basic grammar learning of JSP

Page instruction Description:

Language: Used to define the scripting language to use; The scripting language used by the language= "Java" definition is java.

ContentType: Defines the encoding of the JSP character and the MIME type of the page response; The MIME type------>mime (Multipurpose Internet Mail Extensions) is the Internet standard that describes the message content type (the following type is text/html; character encoding is utf-8).

Pageencoding:jsp the character encoding of the page; The following character encoding is utf-8.

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "

pageencoding= "Utf-8"%>

Scriptlet Tags:

through The scriptlet tag we can embed java code in the JSP ;

The First kind:<%!%> We can define global variables, methods, classes in it;

The second kind:<%%> We can define global variables and write statements in them;

The Third Kind:<%=%> We output a variable or a specific content inside;

For example, code:

<%!

String str= "global variable";

public void Fun () {

System.out.println ("global Method");
}
public class a{
private int b=1;
public void Fun1 () {
SYSTEM.OUT.PRINTLN ("Global Class");
}
}
%>
<%
int a=1234;
String b= "Java";
Out.println (b+a+ "local variable");
%>
<%=b%>

JSP comments:

<!---->html Note client visible

<%----%>jsp Note Client is not visible

Java Single-line comment not visible

/* */java Multi-line annotations are not visible

Code:

<!--HTML comment client Visible-
<%--JSP Note Client is not visible--%>
<%

int Temp=1;//java single-line comment
/* int c=2;
int d=3; Multiple lines of Java comments
*/
%>

JSP contains directives:

<%@ include file= " the files to include " %> static contains first, post-compile processing;

<jsp:include page= " the files to include " > dynamic contains the first compile processing, after the inclusion;

Later we use dynamic inclusion;

Code:

<% @include file= "common/head.html"%>
<p>content content!! </p>
<% @include file= "common/footer.jsp"%>

<jsp:include page= "common/head.html" ></jsp:include>
<p>content</p>
<jsp:include page= "common/footer.jsp" ></jsp:include>

JSP Jump command:

<jsp:forward>

<jsp:param value= "" name= "" >

</jsp:forward>

Server internal jump, can take parameters;

<jsp:param value= "" Name= "" >

Code:

forward.jsp

<jsp:forward page= "target.jsp" >
<jsp:param value= "java" name= "username"/>
<jsp:param value= "123456" name= "password"/>
</jsp:forward>

target.jsp

<p>username:<%=request.getparameter ("username")%></p>
<p>password:<%=request.getparameter ("password")%></p>

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.