what is JSP. Jsp:java server Pages, which is fundamentally a simplified servlet design, implements the use of HTML tag JSP in Java as a Dynamic Web-page technology standard and a JEE standard JSP, like the servlet, is executed on the server side
JSP is Servlet,servlet is not JSP common Dynamic Web site development technology comparison Jsp:java platform, high security, suitable for large-scale development, enterprise-class web programs. Suitable for enterprise-class web development. E-Bank, online Securities Exchange, China Mobile online business Hall, Chinese railway online booking system Asp:. NET platform, easy to learn. But security and cross-platform performance are poor. asp.net torah Drag visual development, Microsoft supporting software Php: simple, efficient, low cost, short development cycle, suitable for small and medium-sized enterprise Web application development.
Development mix: LAMP (operating system linux+ Server tomcat+ database mysql+php)
are the server Page sp. composition of JSP page elements static content: HTML element Small script: <% in this is all small script%> comments:
In addition to HTML annotations (client visible),
There are JSP comments <%--JSP annotation--%> (client is not visible),
Java comments in the JSP script total three kinds of annotations
Instructions:
<% @page import= "java.util.ArrayList"%>
<%@ page language= "java" contenttype= "text/html; Charset=utf-8" pageencoding= "UTF-8"%>
Statement
<%!
"Declaration" (declaring functions and variables)
String s = "Zhangsan";
int add (int x, int y) {//Compute X+y value return
x+y
}
%>
An expression
<!--"expression", do not need a semicolon-->
Hello, <%=s%><br>
x+y=<%=add (10,5)%><br>
Sample
<!--This is the "instruction" page, which controls document type, encoding, importing Java classes, etc.--> <% @page import= "java.util.ArrayList"%> <%@ page language= "Java" Contenttype= "text/html;
Charset=utf-8 "pageencoding=" UTF-8%> <!--pageencoding The encoding of the JSP file itself contentType the content encoded by the CharSet server when it is sent to the client --> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
directives
There are three kinds of JSP directives: page instruction include instruction taglib instruction page instruction
Features: Used to describe the properties of a page language properties: Specify scripting language, only support Java Import properties: Import package instructions, the only one can be used multiple times, import multiple packages can also use "," Split package name
pageencoding Properties and ContentType Properties :
are set to encode and decode, however, pageencoding is the JSP page saved to the hard disk, encoded in the Code table. and ContentType on behalf of the server to send JSP data to the client, this JSP decoding table, these two code tables should be the same, otherwise there may be garbled situation.
Note: After setting one of the properties, the value of another property becomes the value of the property, which means that the server automatically converts the Code table.
AutoFlush Properties and Buffer properties: JSP output to the browser, the output process, when the buffer is full, whether automatically refresh the data in the buffer. You can also use buffer to set the size of the buffer. View the built-in out objects in detail.
<%@
autoflush= "true" buffer= "8kb"
%>
ErrorPage and Iserrorpage: Specify the page that handles the exception, whether to handle the exception, see the built-in exception object
If an exception occurs, jump to the Iserrorpage page
<%
errorpage= "/page/error.jsp"
%>
To set the current page as an exception-handling page, you will get a exception built-in object to receive the exception.
<%
iserrorpage= "true"
%>
the correct way to handle exceptions
Although the above method can be used, but too cumbersome, we can in web.xml based on the HTTP status code settings to the page.
<error-page>
<error-code>404</error>
<location>/page/error.jsp</location >
</error-page>
As long as there are 404 errors, you will jump to the error.jsp page to deal with.
You can also make the appropriate handling according to the exception:
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/ Page/error.jsp</location>
</error-page>
As soon as it appears, java.lang.Exception jumps to the error.jsp page extends property: Inherits the property, specifies a parent class, must be a Servlet info property: Specifies the Jspgetservletinfo value Iselignored property: The switch of El expression, by default you can use the Session property: Boolean, whether to use the session object, or false to use the session built-in object include directive directly
Static contains directive file attribute:
<%@ include file= "/page/child.jsp"%>
Static inclusion principle:
So merge, in the same Java class, notice the declaration of the variable
Role: Introduce content, merge pages into code, and invoke methods in the code being introduced.
Dynamic Inclusion principle:
taglib directives
Import Label Directives use El expressions instead of JSP expression scripts
Used instead of <%=%> expression scripts.
Format: &{expression}
Mainly used in four domains to remove data (application,request,session,page), that is, simplifying getattribute ... and other operations.
Like what
<%
request.setattribute ("name", "Feathers");
%>
name is: ${requestscope.name} <!--to remove the value in the Request field with key name-->
Attention:
If you write ${name this way, if you do not specify a field, you will find it from small to large fields.