Java Web Development Combat Classic (I)

Source: Internet
Author: User

One, JSP three kinds of scriptlet (script applet)

1, <%%>: Define local variables, write statements, and so on.

<%  = "Hello world!" ;//define local variable  out.println (str);//write Statement %>

2, <%! %>: Defines global variables, methods, and classes. (although this party can write classes, it is not recommended.) We usually call the class by JavaBean form)

<%!   Public Static Final String INFO = "JAVA Web"; //define global variables %><%!   Public int Add (intint  y) {//define method      return x+y;  } %><%!   class person{//defines the class   }%><%//writes the normal script out.println ("INFO");//Call global variable out.println (add ( 3,5));//Call Method %>

3, <%=%>: Lose a variable or a specific content

<%   = "java"; %>//Using an expression output variable 

Second, including

1. Static inclusion
<%@ include file= "a.html"%>

<%@ include file= "a.jsp"%>

2. Dynamic inclusion

2.1 With no parameters

<jsp:include page= "a.html"/>

<jsp:include page= "a.jsp"/>

2.2 With parameters

<jsp:include page= "a.jsp" >//pass two parameters to the included page

<jsp:param name= "name" value= "<%=username%>"/>

<jsp:param name= "Info" value= "java Web"/>

</jsp:include>

Static is the first containing the re-processing, dynamic is the row after the inclusion, so we should be more dynamic inclusion.

Example: a.jsp file

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" ><%@ page contenttype= " TEXT/HTML;CHARSET=GBK "pageencoding=" GBK "%><%  int i = +; %>

index.jsp

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" ><%@ page language= "Java" pageencoding= "GBK"%><%@ include file= "a.jsp"%>//static contains <%   int i=10; %>

If static loading will be an error, because the static is merged and then processed, when the merge is defined two the same I variable, so show the times wrong.

However, if it is dynamic, then the merge is processed first, so two results can be displayed normally.

Java Web Development Combat Classic (I)

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.