1 The origin of JSP
Servlet generation, there is a big problem, in order to show the effect of the page, you need to output a large number of HTML statements, expressed as a string, not only conducive to development, but also not conducive to the maintenance of the later, resulting in JSP. It is primarily used to extract the statements that are responsible for display in the servlet. When a JSP file is written out, it will eventually run through the JSP.
2 What is a JSP
is a component specification for a server-side dynamic page technology developed by Sun.
3 syntax
<% for (int=0< ; I+ +) { %>
Code blocks, also known as scripts
Shown in the servlet as
Out. Print (3+5); out. Print (add()); Print (Xx.getname ()); Print (Xx.getname ()+"abc"));
<%= 1 + 2 %>
Output statement, expressed as
Out.println (1+2);
Instructions in a JSP page
<%@ instruction name attribute =%>
Common directives include the following three types of
Page directive
Include directives
TAGLIB directive
The page directive allows you to import the Java package you want to use in your JSP page, or you can set some properties of the page
<%--Guide Pack--%><%@ Page Import="Java.util.*“%><%@ Page Import="Java.util.*, java.sql.*“%><%--sets the parameter value of the Response.setconenttype method--%><%@ Page ContentType=“text/Html;charset=Utf-8“%><%--sets how the container decodes the file when it is read--%><%@ Page pageencoding="UTF-8“%>
The include directive is used primarily to include other pages in another page. Many pages in the same application will have the same navigation head, copyright notice, repeated in each page is not necessary, and if the navigation head changes when it is not conducive to all page updates. If you make such a common part of a file alone, you only need to add a reference to different pages, you can implement page content reuse.
<% file = %>
JSP Implicit Object
Since the JSP page eventually translates into a servlet, and as a previous version of the servlet that is about to be transformed, there are many systems available to the page to use directly, the creation of these objects is done by the system, the object name is also system named, according to the function of the page to be implemented directly to use.
These hidden objects can be used directly in the JSP
JSP Basic Syntax