1. Session Management:
1) URL Rewrite: (Small information section use this method)
Usually use a tag: url?key=value&key2=value2 ....;(URL and token build? Separated by & between tokens);
--------------------------------------------------------------------------------------------------------------- -----------------------------------
2) Hidden fields: (valid only when a Web page has a form, but not as good as URL rewriting across multiple interfaces)
<input type= "hidden" name= "value=" ">//this hidden field can follow form submission
--------------------------------------------------------------------------------------------------------------- -----------------------------------
3) *cookies: (can pass information between multiple pages)
Create a Cookie:cookie cookie = new Cookie (key, value);//The domain, path, MaxAge property can be set after creation, MaxAge is the life cycle
Httpservletresponse.addcookie (cookies);//Send cookies to the browser
Servletactioncontext.getresponse (). Addcookie (cookie);//This method is suitable for use in struts2
When the browser accesses the server, it will send the previously received cookies to the server * * *
Server Gets Cookie method:
cookie[] cookies = request.getcookies ();
Cookie cook = null;
if (cookie = null) {
for (Cookie ck:cookies) {
if (Ck.getname (). Equals ("name")) {
Cook = ck;
Break
}
}
}
How to delete an existing cookie: (Create a cookie with the same name and set MaxAge to 0)
Cookie cookie = new Cookie ("name", "" ");
Cookie.setmaxage (0);
Httpservletresponse.addcookie (cookie);
The front desk Gets the cookie method:
A. Guide Jquery.cookie.js:$.cookie ("key");
B. Using the EL Expression: ${cookie.cookiekey.value}//to obtain the cookie value; ${cookie.cookiekey.path}//get the path value of the cookie
--------------------------------------------------------------------------------------------------------------- -----------------------------------
4) ***httpsession object: (most powerful and applicable) (memory occupied)
HttpSession getsession ();//Use the GetSession (). SetAttribute () method to save values to the session; GetSession (). getattribute () value;
Deployment Descriptor Session-timeout Set the session expiration time;
Setmaxinactiveinterval set the time separately for a session;
=============================================================================================================== ===================================
2. El expression language: ${}
1) Accessing object properties:
${object.name} or ${object["name"} The latter is more canonical
2) Visit JavaBean:
${bean.stu_name}//accessing the Stu_name property in a bean
3) Relational operators:
${statement? a:b}//If the result of the statement calculation is true, the output of a, if false, results b
4) Empty operator:
${empty x}//if X is a string of length 0, or is an empty map, an empty array, and an empty set, Ze returns True
=============================================================================================================== ===================================
3. Jstl Label:
<%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>
1) Set Label:
The following creates the string, the wisest fool, and assigns it to the page range variable fool
<c:set var= "Fool" value= "the Wisest fool"/>
The following creates the job's bounded variable, referencing the requested scope of the object position
<c:set var= "Job" value= "${requestscope.position}" scope= "Page|request|session|application"/>
The following set is the city property that assigns the string "Tokyo" to the address of the bounded object
<c:set target= "${address}" property= "City" value= "Tokyo"/>
--------------------------------------------------------------------------------------------------------------- -----------------------------------
2) Remove Label:
Used to delete a bounded variable, but cannot delete the referenced object
<c:remove var= "VarName" [scope= "Page|request|session|application"]/>
--------------------------------------------------------------------------------------------------------------- -----------------------------------
3) If tag: Determines the result of the operation in test, if true, executes the body content, otherwise does not execute. Two <c:if> tags can be used in order to imitate if...else, the condition setting is completely opposite
<c:if test= "Testcondition" [var= "VarName"] [scope= "Page|request|session|application"]>
Body Content
</c:if>
--------------------------------------------------------------------------------------------------------------- -----------------------------------
4) Choose, when, and otherwise tags: (similar to switch and case in Java)
<c:choose>
<c:when test= "Testcondition" >
Body Content
</c:when>
<c:when test= "TestCondition2" >
Body Content
</c:when>
<c:otherwise>//in the end, when all of the above are false, perform the body content in otherwise
Other body content
</c:otherwise>
</c:choose>
--------------------------------------------------------------------------------------------------------------- -----------------------------------
5) foreach tag:
Traverse the collection collection to display the value of the Stu_name property
<c:foreach items= "collection" var= "VarName" [varstatus= "num"] [begin= "Begin"] [end= "End"] [step= "Step"]>
${varname.stu_name}
</c:forEach>
Used in conjunction with map
<c:foreach item= "Map" var= "VarName" >
${varname.key}
${varname.value}
</c:forEach>
--------------------------------------------------------------------------------------------------------------- -----------------------------------
6) Fortokens tag: Used to traverse a string separated by a specific delimiter, etc.
<c:fortokens var= "Item" items= "A,b,c,d" delims= "," >
<c:out value= "${item}"/>
</c:forTokens>
--------------------------------------------------------------------------------------------------------------- -----------------------------------
<%@ taglib uri= "http://java.sun.com/jsp/jstl/functions" prefix= "FN"%>//the format of the calling function to be used with the EL Expression: ${fn:functionname}
7) contains function: Used to test whether a string contains the specified substring (the Containsignorecase function is similar to contains but case-sensitive)
${fn:contains (myString, "Hello")}//determine if the myString string contains a hello
--------------------------------------------------------------------------------------------------------------- -----------------------------------
8) Endwith function: Used to test whether a string has a specified suffix ending (startwith opposite)
${fn:endwith ("Hello World", "World")}
--------------------------------------------------------------------------------------------------------------- -----------------------------------
9) indexof function: Used to return the index of the specified substring when it first appears in a string
${fn:indexof ("Hello", "E")}//returns 1
--------------------------------------------------------------------------------------------------------------- -----------------------------------
) Join function: Used to split an array with a specific symbol
${fn:join (Array, ",")}
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Length function: Used to return the item book in the collection, or the number of characters in a string
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Replace function: Replaces all occurrences in a string with after
${fn:replace ("Hello World", "L", "L")}//result for Hello World
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Split function: Used to separate a string into an array of strings, as opposed to a join
${fn:split ("My,world", ",")}
--------------------------------------------------------------------------------------------------------------- -----------------------------------
SUBSTRING function: Returns a substring from the specified starting index to the terminating index (the Substringafter\substringbefore function returns the portion of the first occurrence of a substring before \)
${fn:substring ("Hello World", 0,4)}
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Tolowercase\touppercase function: To convert a string to lowercase \ Uppercase version
--------------------------------------------------------------------------------------------------------------- -----------------------------------) Trim function: Used to delete whitespace at the beginning and end of a string
${fn:trim ("Hello")}//return Hello
=============================================================================================================== ===================================
Servlets and JSPs