JSTL and EL of Java_Web, JSTLEL of Java_Web
I learned JSTL and EL today and replaced the previous for loop. I feel that the code is getting fewer and fewer, which is very convenient. JSTL and EL are inseparable.
1. What is an EL expression?
What is EL? Expression Language EL replaces the syntax $ {EL exprission }$ {bean. name} or $ {bean ['name']}
Ii. EL features
Automatic Conversion Type
The data type can be automatically converted when EL obtains data.
The restrictions on types are more relaxed. Compared to embedding Java code in JSP, EL application is simpler. 3. EL syntax starts with "$, use "}" as the end to get the value $ {username} by using the variable name. Variable attribute range name 4. Operators in EL and EL implicit objects
EL operator "[]" operator "." is used to obtain object attributes. Data in the object set is saved in the Session as a list set of users.
What is JSTL?
Using JSTL to implement logic processing in JSP pages what is JSTLJSTL (assumerverpages Standard Tag Library) JSP Standard Tag Library JSTL usually works with EL expressions to implement JSP page Encoding
2. JSTL Environment Construction
Use the JSTL step to create a Web project and select JSTL1.1 (the current version does not need to be configured, and the later version is collected together). Add the taglib command on the JSP page to use the JSTL tag.
Introduction to JSTL standard tag Library
Common labels
Condition tag
Iteration tag
JSTL and EL Cases
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; session. setAttribute ("username", "James"); List list = new ArrayList (); list. add ("a"); list. add ("B"); list. add ("c"); list. add ("d"); request. setAttribute ("aa", list); Map map = new HashMap (); Map. put ("name", "admin"); map. put ("pwd", "adminpassword"); request. setAttribute ("map", map); session. setAttribute ("map", map); application. setAttribute ("c", "123456"); application. setAttribute ("c", "789"); entity. user user = new entity. user (); user. setUsername ("aa"); user. setPassword ("bb"); session. setAttribute ("user", user); // request. getParameter (); // ------ param: Get the form item // request. getParameterValues ();// ------ ParamValues: Get multiple form items %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
Processing page
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% @ taglib uri =" http://java.sun.com/jsp/jstl/functions "prefix =" fn "%> <% @ taglib uri =" http://java.sun.com/jsp/jstl/core "prefix =" c "%> <% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; String name = request. getParameter ("username"); String [] Love = request. getParameterValues ("love"); %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">