JSP, Java Server Page
A JSP page is a page that runs on a server
Dynamic Web pages
Pages with data interaction in the background
Differences from other languages:
JSP developed in Java language, high security, suitable for large projects, enterprise-class text application
Distributed projects, server clusters, Hadoop
ASP. NET uses C #,. NET platform, easy to use, because not open source, so security is low, and can not cross platform
Use. NET development projects, preferably using Windows systems and SQL Server databases
PHP simple and efficient low-cost development cycle, suitable for small and medium-sized enterprise Web application development
PHP Gold Partner---(Lamp:linux, Apache, Mysql, PHP)
About Tomcat
Conf---all configurations of tomcat
WebApps---Projects that need to be deployed
Work---Files compiled after Tomcat is run
Lib the jar files required to run the Tomcat server
Run the project's virtual path
Right-click Items--Properties--Web project Settings---Change this name to modify the project's virtual path
Re-deploy the project and restart Tomcat when you are finished changing
The constituent elements of JSP;
1, instruction
Page directive
<%@ page ..........%>
Language---Current page language: Java
Import---The class library introduced by the current page, which is not introduced by default
ContentType---text/html; charset= ' character set '
Iso-8859-1 is the default value of the character set, and the plain English character set
Include directives
TAGLIB directive
2, expression
<%= Variable name%>
3, Script
<% Code Content%>
4, statement
<%! Code Declaration%>
5, Notes
Visible <!---->
Invisible <%----%>
Comments used in the script
/**/, //
? 6, some static content
JSP nine large built-in objects:
5, Response Response object
6, page current object
7, out output stream object
8, exception exception
9, config Servletconfig/filterconfig object
Scope (the lifetime of each scope is different):
1, Application global scope
2, Session scope
3, request scope
4, PageContext page scope
Priority (by life cycle):
Application > Session > Request > PageContext
ai pu ' lei kei Shen>sai ' Shen>rui ' Form form submission method in Kuai ' si ' t>pei ' zhi ' kang ' tai ' si ' t
Page:
Post:
Submission is not visible, no length limit
Get:
has length limit, The submission is visible in the address bar
Request object:
The Request object is an instance of the class HttpServletRequest
Common method:
String GetParameter (string name)- --Returns the value of the parameter specified by name
string[] Getparametervalues (string name)---Returns an array of all people that contain that parameter name
void SetAttribute (String, Object)---Set the property in a scope
Object getattribute (string name)---Get the property in a scope
String getservername ()---Return the host name of the requesting server The
String getContentType ()---Returns the MIME type of the request body
String Getprotocol ()---Returns the protocol type and version number for the request
Int getserverport ()--- Gets the port number of the server
int getcontentlength ()---Returns the length of the request body (in bytes)
String getremoteaddr ()---Returns the IP address of the client that sent the request
String Getrealpath (string path)---Returns the physical path of the passed-in path
String getcontextpath ()---Returns the context path
Solve the problem of Chinese garbled characters in request
Post mode:
By using request.setcharacterencoding ("Utf-8") to set
Get mode:
Set up by modifying the Server.xml configuration file in the Tomcat server
Response Object
Response object is an instance of HttpServletResponse
Common methods;
Setcharacterencoding (String name)---Set the character encoding used by the response page
setContentType ("text/html; Charset=utf-8 ")---set (MIME type) Request header
Response.getwriter (). Append (string content)---output a string to a page
The type of the Out object is JspWriter, and Response.getwriter () is a printwriter, and the Out object can also be obtained by Pagecontext.getout (), and the two objects are of different types
Out.print (null); Throws an exception, printwriter.print (NULL) does not throw an exception
JspWriter is an abstract class, and PrintWriter is an ordinary class that inherits writer.
The Getwriter () method can output a string of characters on the page, and out is also an output object, the difference being that the result of the Getwriter () method, always takes precedence over the Out object, can use the Out.flush () method to force the contents of the property buffer, Outputs the output of an Out object first
Causes of this phenomenon:
The Out object is actually dependent on the printwriter, he needs to save the output to the response buffer, and then wait for the JSP page out to meet certain conditions before the output method will be called to output the content directly to the page
And printwriter can be directly output.
Forwarding and redirection (interview 98% will ask)
Response.sendredirect (String location)---request redirection
Client behavior, essentially equivalent to two requests, the first requested object will not be saved, the Address bar URL will change
Request.getrequestdispatcher (). Forward (request, response)---request forwarding
Server behavior, the equivalent of a request, after forwarding the request object will be saved, the Address bar URL will not change
Example: Certificate
Session Object
Session refers to the time when a user enters a Web site to close the browser, the default session of the TOMCAI server is 30 minutes, that is, open a website for 30 minutes without action, the session object will also expire
Session exists in the server's memory, the server of different users corresponding to the session is also different, so the server is used to determine whether the current logged on the user is the same time need session
Session object is an instance of HttpSession
Common methods:
Long GetCreationTime ()---Returns the time the Session object was created
String getId ()---Returns a sessionid that is unique
void SetAttribute ()---Set a property and a property value
Object getattribute ()---Gets the property value of a property
String[] GetValueNames ()---Gets the property names of all the available properties in the session object as an array
Setmaxinactiveinterval ()---Set how long the session expires (default 30 minutes)
Getmaxinactiveinterval ()---Set the session's expiration time in seconds
The session life cycle:
Create: When a user accesses a JSP or servlet for the first time, the server creates a session for the current access and generates a SessionID, which is validated every time the client sends a request to the server.
Activities: In this page of various activities, such as open another page through the Super connection, or do a variety of additions and deletions to change the operation, the session expires unless you wait until the browser's relevant page is closed, or the session timeout, when re-visit will create a new session, But the original session will still exist, but there is no request to bring the old SessionID to the server to verify the
Destroyed:
Three ways to destroy session
1, call the Session.invalidate () method
2, the session itself expired
Setting the session expiration time can also be set in Web. xml
<session-conf>
<session-timeout>
10<!--Unit is minutes! -
</session-timeout>
</session-conf>
3, Server restart
Javaweb JSP Finishing