In the previous article, we simply review the following JSP and briefly introduce how to execute a JSP file. Below we will focus on JSP TAG. And review the basic knowledge of JSP when necessary. First of all, let's introduce a basic JSP grammar: As foregoing, JSP can not only handle static content, but also handle the dynamic content. But to deal with dynamic content, you must be able to define methods, create, access objects. Below we will start from a few typical examples to see how you should do:
1. <% @ page import = "java.util. *"%> When you look at it, you have to use this format to declare in the JSP when you want to use your own definition.
2. <%! Private static int guestnum;
Public void jspinit () {...} public void jspdestroy () {...}%> The above format is used to declare variables and implementation methods. If you can initialize JSP in JSPinit (), in JSPDestory (), you can implement some work that should be made when the JSP page stops service (note that the variables so declared, and the method will become JSP after compiling Global variables, and methods in corresponding servlets.
3. <% out.write (Request.getRequesturi ());%> The above is used when adding various scripts in the middle of HTML. Different from 2, all code in compiling 3 will be inserted into the service method in the corresponding servlet, of course, the variables declared here are local variables. 4. <% = "Hello"%> This is the method mentioned last time.
Ok, this is the basic syntax of JSP. With them, we will now take the following, perform the following JSP (see the following method to see the following):
<% @ Page ContentType = "Text / HTML; Charset = GBK"%> <% @ page import = "java.io. *"%> <% - this is the method of comment -%> <% // of course This is also possible with%>
<% - 2 Definition -%> <%! Private static int guestnum; public void jspinit () {guestnum = 0;}%>