Part 1: items created by default in JSP files.
Take myeclipse8.0 as an example to create a new JSP file. The following code is created by default.
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Line 3 illustrates that the language used on this page is Java, the Java package introduced, and the encoding method. The preceding content starts with "<% @ page" and ends with "%>. You can also put it in multiple rows. If you put it in multiple rows, each row requires a start and end sign.
Java is the default package imported during JSP compilation. lang. *, javax. servlet. *, javax. servlet. JSP. *, javax. servlet. HTTP. * The preceding package does not need to be imported.
Encoding method. If you want to use an intermediate file, you can select gb2312 or GBK as the encoding method.
<HTML>
If you want to change the content displayed on the page, modify it in <body> </body>.
The basic syntax for inserting Java code in JSP.
1. Declare the variable <%> or <%! %>
<%! %> The declared global variable can be used in the entire JSP file. <%> the declared variable can only be used after the declared position.
Example:
<%!int a=3; %>
2. Insert General Java code <%>
Example:
<%int a=3;%> <%a++; %>
3. Insert expression <% = %>
Example:
<%int a=3;%> <%a++; %> <%=a %>
Add the preceding content in the middle of <body> </body>, run tomcat, and access the page in the browser. The page is displayed.
4. Insert comments <% -- %> or <%/**/%>
The client does not see the content in the comment when viewing the source code, which is highly secure.
If an HTML comment is inserted, the format is <! -->
You can see the comments when viewing the source code.