JSP basic syntax
1. dynamic page technology (jsp)
What is jsp? Java server page technology.
Jsp includes static and dynamic parts and runs on the server.
Html contains java code, which must be run on the server to complete the process of translation, compilation, and running. Finally, html is returned to the client.
The final generation of java and class files are all stored in the tomcat work directory.
Work/Catalina/localhost/project name/org/apache/jsp/Page name_jsp. java and the java file is a final class.
2. jsp page composition: Template elements and jsp Elements
Template elements: html, css, javascript, etc.
Jsp elements: script elements, comment elements, instruction elements, and Action elements
Script elements: script segment, declaration, expression, EL
The variables defined in the script are local variables, and the methods cannot be defined.
The variables defined in the Declaration are global variables that can define methods. Any user's operations on the global variables on the jsp page will affect other users.
3. syntax used for script segments: <% valid code segments; %> Each jsp page can use any number of script segments.
4. Statement Syntax: <%! Declare 1; declare 2; ...... %>
5. expression: <% = valid java expression (the end cannot contain a seal) %>
6. A summary of some practical syntaxes:
Html comment
<% = %> Expression
<%> Script segment
<%! %> Declaration
<% -- %> Jsp comment
<% @ %> Command element
7. Three main command elements: page, include, and taglib
Page command attribute: language used by the script Element
PageEncoding: character encoding
ContentType: The type and encoding format of the output content.
Info: Page Description
Import: java class packages required for the import page
Session: sets whether the built-in session object on the current page is available.
IsErrorPage: Specifies whether the page is an exception handling page during the schedule.
Buffer: Set the buffer size of the out object or disable the buffer.
Include: This command appears on the jsp page. It contains a static file (which must be parsed by jsp and stored in the same page as the current jsp page ).
Static includes: the current jsp page and the inserted part form a new jsp page, and then the jsp Engine translates the jsp page into a java file. Note: only one java class file is generated under the work directory.
Problems: the same variables appear on the current jsp page and some inserted pages, causing compilation errors.
Taglib: used to introduce the required tag library definition to the jsp page. The syntax format is as follows:
<% @ Taglib uri = "mark library uri address" prefix = "prefix name" %>
8. Eight built-in jsp objects -------- out
The out object is mainly used to output data to the browser. Common methods include print (), println (), and close ()
The difference between the print and println Methods: not the displayed page line feed, but the generated html source code line feed
See the example below: jsp code
Let's see the result of running in the browser:
There seems to be no difference above. The difference lies in the source code.
Okay. Next time, write other built-in objects and action elements.