1. Why do you need jsp ?
Servlet is very convenient for logic processing, but it is very troublesome for page display. The birth of JSP is to solve the problem of troublesome servlet page display.
2. Features of JSP :
Jsp page display is very convenient, but business logic processing is very troublesome
Summarize:
Generally, we need to combine the two technologies, Servlet for business processing, and jsp for page display
jsp specific content:
Jsp principle: (jsp is Servlet) When we access the jsp file, we do not directly execute the JSP file, but are intercepted by the server to execute the class of jspServlet . This class will translate the jsp file into the corresponding servlet file and execute it. So the essence of jsp is Servlet .
Use of jsp :
1. Common instruction set:
page
language declares the languages supported by the jsp file
import package when translating
pageEncoding --> set the encoding format of translation and client-side presentation data
session -->true means use session object ( default ) false does not use session object
errorPage -->jsp running error will automatically jump to the specified page
include:
Static import:
Translated into a Servlet class ( variables with the same name cannot appear ) , high coupling
Dynamic import:
Translated into two Servlet classes ( variables with the same name can appear ) , low coupling
forward:
Request forwarding (with return ) :
<jsp:forward page=" The path of the file to be forwarded ">
<jsp:param value="值" name="键"/>
</jsp:forward>
2 , java code segment declaration
<%java code %>--- will be translated into _jspService method, local code
3. Global code segment declaration
<%! Declaration method %>---- will be translated into global code
4. Expression statement ( important )
<%= variable name / method %>--- can not add a semicolon after
Note: Be sure not to add a semicolon, it is equivalent to out.write() , which will respond to the client with the value inside
5. Nine built-in objects:
Four scopes:
pageContext page context object, this object encapsulates the acquisition method of other objects, the current page ( understand )
request is actually the request object, which is used in the same way as Servlet
Session is actually a session object
The application is actually the ServletContext object
Two outputs:
out output object
response output object
Three soy sauces:
page represents the page object
config ServletConfig
exception exception object, discarded
6. Notes
HTML comments:
will be translated and sent to the client
css comments:
will be translated and will be sent
js comments:
will be translated and will be sent
java annotation
will be translated
jsp comments:
%-- Comment content --% Do not translate directly