JSP Programming Development tutorial and programming development tutorial
JSP Introduction
1.JSP: Java server pages, that is, the java server Page.
2. JSP is a set of dynamic web page technical standards. This standard is implemented by major web server vendors.
3. We need to input the main method in the source code to run a java program. However, we do not need to use the main method to learn JSP technology. A JSP page must have a web server for parsing and running. Note that jsp files cannot be run by double-clicking, opened by a browser, or compiled by javac. They must be run on the web server.
How to Use tomcat (deploy web applications)
1. Enter % atat_home %, enter the bin directory, and select starup. bat. A window will appear after double-clicking: do not close the window.
2. test whether the tomcat service is successfully started: Open the browser and enter the URL: localhost: 8080. If the following page appears, it means the startup is successful.
3. Enter the webapps directory in % atat_home % again and create a folder by yourself. However, the folder cannot be named in Chinese. Enter the folder, create a jsp file in the folder, and enter http: // localhost: 8080/foo/a in the address bar of the browser. jsp can run jsp files (foo is the folder name,. jsp is the created jsp file ).
Note:: You must ensure that JDK is installed on your computer and the java_home environment variable is configured to start tomcat.
JSP running principle
Note::
1. jsp files cannot be directly executed. jsp is just a draft to generate a java source file;
2. The java source file cannot be executed. The java source file is to be compiled into a class file by javac;
3. We finally run the class bytecode file.
Conclusion: jsp> java> class
Integrate tomcat in the myeclipse Environment
1. Click the triangle shown in the figure:
2. Select Configure Server:
3. Select Server> Tomcat 6.x:
4. After enable is selected, you only need to click the first browser button and select the tomcat root directory. You do not need to worry about the following items:
After completing the preceding steps, tomcat is deployed. After creating a jsp file, click the deployment button and start the server. Then, you can type an address in the browser to run the jsp file. Note that in some myeclipse versions, you do not need to integrate tomcat through the above steps. Simply click the deployment button in myeclipse and start the server.
Various elements in jsp
1. Script element:
<%>
<%! %>
<% = %>
<%--%>
2. command element:
Page
Include
Taglib
3. Action elements
Jsp script Element
1.Script Element:
(1)<%>
The content in this script segment will eventually appear in a java method.
So what content can be written in java methods can be written in <%>;
Java methods cannot write anything, but <%> cannot.
(2)<%! %>
The content in the script segment will appear in the class outside of the method.
So what content can be written outside the method in java class, at <%! %>;
Nothing can be written outside the method in the java class, at <%! %> Cannot write anything.
(3)<% = %>
The content in the script segment will eventually become a parameter of out. print.
So what content can be written in java method parameters can be written in <% = %>;
Java method parameters cannot write anything. in <% = %>, nothing can be written.
(4)<%--%>
The content in the script segment is used to tell the web server to ignore the content in the script when parsing a jsp file into a java source file, that is to say, the content in the <%--%> script will not appear in the java source file.
Comparison: /// **/the content of the comment will appear in the java source file.
Comparison:It will not only appear in the java source file, but also be sent to the client browser by the server.
Note: OnlyCan be seen in the source code of the client browser. Therefore, there are two terminologies:
Client notes:
Server Note: <%-%> ///**/
2.Note:: Jsp will instantiate the object only when it is accessed for the first time, such ,......, When you access the same jsp page n times, the instance created for the first time is used.
Page directive Element
1.Command element: All directive elements are <% @ %>
2.PageTo learn the page directive element is to learn the attributes of the page directive element. Common attributes include: