1. Understand JSP
1.1 Basic Knowledge
Java Server Pages dynamic web page technology
ASP: VB and JS as scripts
JSP: Java Dynamic and Static Page Separation
Run after compilation from the hardware platform
Basics: Java and HTML
1.2 JSP page
The xxx. jsp page consists of HTML tags and <%> Java programs. The names are case sensitive.
Running principle: the first request is that the JSP engine on the server first translates the JSP page file into a Java file and then compiles it into a bytecode file. Subsequent requests directly execute bytecode files-so the speed is fast.
1.3 environment Configuration
Environment Elements: JDK + Tomcat + eclipse (simply execute JSP programs, as long as JDK and tomcat are required, eclipse facilitates Program Development and debugging)
Java_home, variable value: C: \ jdk1.3
Path, variable value: C: \ jdk1.3 \ bin
Classpath, variable value: C: \ jdk1.3 \ JRE \ Lib \ RT. jar;
Tomcat_home, variable value: D: \ Tomcat \ Jakarta-tomcat-4.0
Start the Tomcat server. Execute startup. bat under Tomcat \ Jakarta-Tomcat-4.0 \ bin, http: // localhost: 8080
Use eclipse to create a web-> dynamic web project
HTML tags: http://www.w3school.com.cn/tags/tag_input.asp
2. Basic JSP syntax
2.1 variables and Synchronization
In "<% !" And "%>" are used to declare variables and methods between the symbols on the entire JSP page. Note: The JSP Engine Starts a thread for each customer, these threads are managed by the JSP engine server. These threads share the JSP page member variables. Therefore, any user's operation on the JSP page member variables will affect other users.
Multiple threads share the same variable. The synchronization mechanism is required here-when a thread is accessed, other threads are waiting:
<%! Integer Number = new INTEGER (0); %>
<%
Synchronized (number ){
Int I = number. intvalue ();
I ++;
Number = new INTEGER (I );
}
%>
You are the <% = number. intvalue () %> customer accessing this site.
2.2 Method
In "<% !" And "%>". This method is valid throughout the JSP page, but the variables defined in this method are only valid in this method. These methods will be called in the Java program. When the method is called
The variables defined in the method are allocated with memory. After the call is completed, the occupied memory can be released.
If multiple customers request a single JSP page at the same time, they may use methods to operate member variables (shared). This requires defining the methods as synchronized.
<%! Int number2 = 0;
Synchronized void countpeople ()
{
Number2 ++;
}
%>
<% Countpeople (); // call the method in the program.
%>
You are the <% = number2 %> customer accessing this site.
2.3 categories and objects
You can go to "<% !" Declare a class between "%>" and "%>". This class is valid on the JSP page. That is, you can use this class to create an object in the Java program part of the JSP page.
<%! Public class circle {
Double R;
Circle (double r ){
This. r = R;
}
} %>
<%
String STR = request. getparameter ("cat ");
Double R;
If (STR! = NULL ){
R = double. valueof (STR). doublevalue ();
} Else {
R = 1;
}
Circle = new circle (r); // create an object.
%>
<P>
The area of the circle is: <br>
<% = Circle. calcmj () %>
2.4 values in the dialog box
<Input type = "text" name = "cat" value = "1">
<%
String STR = request. getparameter ("cat ");
%>
2.5 annotations
HTML <! -->
JSP <% -- %>
2.6 JSP static call JSP
<% @ Include file = "computer. jsp" %>
3. jsp Communication
<Form> is a form tag. The value of method is get or post. The main difference between the get method and the post method is that the information submitted using the get method is displayed in the address bar of the browser during the submission process, the information submitted by the POST method is not displayed in the address bar. The submission methods include text box, list, and region. For example:
<Form action = "Tom. jsp" method = "Post">
<Input type = "text" name = "boy" value = "OK">
<Input type = "Submit" value = "send" name = "Submit">
</Form>
This form uses the POST method to send messages to the page Tom. JSP submits information by entering information in the text box. The default information is "OK". Then, click "send" to send the information to the server's JSP page Tom. JSP submits information.
<Form action = "test_class_get_post.jsp" method = post name = form> indicates to the page itself
The request object can use the getparameter (string s) method to obtain information submitted by the form through text,
For example: request. getparameter ("Boy ");
Chinese Character Processing: if the form receives Chinese characters, it must be processed; otherwise, garbled characters are displayed.
String STR = request. getparameter ("girl ");
Byte B [] = Str. getbytes ("ISO-8859-1 ");
STR = new string (B );
3.1 form
<Form method = GET | post action = "destination Page for information submission" name = "form name">
Data submission methods
</Form>
The data submission method of a form usually includes the following markup symbols:
<Input...>
<Input type = "text" name = "me" value = "hi" size = "12" algin = "Left" maxlength = "30">
<Input type = "radio" name = "rad" value = "red" algin = "TOP" Checked = "Java">
<Input type = "checkbox" name = "ch" value = "pink" algin = "TOP" Checked = "Java">
<Input type = "passwordt" name = "me" size = "12" maxlength = "30">
<Input type = "Submit" name = "me" value = "OK" size = "12">
<Input type = "reset">
<Select... > </SELECT>
<Select name = "Shulie">
<Option value = "cat"> you selected a kitten.
<Option value = "dog"> you chose a puppy.
<Option value = "600"> N = 600
</SELECT>
<Option...> </Option>
<Textarea...> </Textarea>
4. JavaBean
Javabean is an encapsulated Java component, that is, some Java classes with fixed functions. jsp programs call beans (class files generated by Java class compilation) to implement these functions.
Beans are mainly responsible for the dynamic part of JSP, while JSP pages are mainly responsible for the static part.
5. Learn how to use built-in JSP objects
6 Servlet
When a customer requests a JSP page, the JSP engine generates a Java file, that is, a servlet, based on the JSP page.