Home > Back-end >  MVC - JSTL - EL - - three layers - SQL data source
MVC - JSTL - EL - - three layers - SQL data source

Time:11-24

Three layers of relationships:
1. The presentation layer to accept the user's request, according to customer's request to inform the business logic layer
2. The data access layer started to access the database after receipt of a request
3. The next layer can't call a layer
4. Do not rely on the next layer on layer
4. A layer cannot appear in the next layer of ci read


Realize the data source connection: the DataSource (data is maintained by Tomcat)
(through jndi data source to obtain data sources not instantiate)
The Context con=new InitialContext ();
//by "Java: comp/env/" as a prefix to access the jndi resources
DataSource ds=(DataSource) con. Lookup (" Java: comp/env/data source ");
The Connection conn=ds. GetConnection ();

The connection pool: Tomcat
(1) is provided by the container
2. To manage the pool connection object
3. The application from the connection pool to obtain objects
4. The connection object in the connection pool is created by the container
5. Can reduce the pressure of the database access
6. Storage is database connection
7. Application finally to use Close () method closes the connection

MVC: JSP three-tier architecture
Serlvet control layer object
V: the presentation layer (VIEW) the JSP is used to display and data access interface
M: control layer (Controller) Servlet control page jump
C: the Model layer (the Model) javabean processing upper transmission of data, and database access data

MaxActive the maximum number of objects can be removed from the object pool for 0 means unlimited default for 8
Minldle object pool objects in the smallest number
Maxidle maximum number of idle connections to
ValidationQuery validation connection whether successful Sql Select command returns a row at least
Maxwait waiting for the second largest number of unit 1 ms to unlimited

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
| String contextPath=request. GetContextPath (); |
| to get the path of the project |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Access to the Servlet initialization parameters:
Initialization parameters configuration [must be in a pair & lt; web - app> inside]

InitParam
Hello Servlet


To obtain parameters:
//based on his name to obtain the value
InitParam String initParam=getInitParameter (" ");


Access to the Servlet context parameters:
Configure the Servlet context [must be in a pair & lt; web - app> inside]

ContextParam The initialization parameter name
Hello Servlet Initialization parameter values


For context parameter:
//the value read according to the parameter name
String contextParam=this. GetServletContext (.) getInitParameter (" contextParam ");

-- -- -- -- -- -- -- System. Out. The println (" the Servlet initialization parameter "+ initParam);
-- -- -- -- -- -- -- System. Out. The println (" System initialization parameter "+ contextParam);


Chapter viii
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- JSTL EL expression -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

EL expression profile:
1. What is el: Expression Language (Expression Language)
2. EL function: replace complex encoding data access in the JSP page
3. The characteristics of the EL: [automatic conversion type] EL can automatic conversion when get a data type is simple to use


EL expression syntax [6-1] :
The ${EL expression}
1. Through the value of the variable name
2. Obtain the object attribute values
3. Get collection element
4. Perform expression


EL expression syntax [6-2] :
The ${variable name}
The code example:
//save the data in the Servlet or JSP
Request. SetAttribute (" username ", "LiYang");
//in the JSP to access data
Name: ${username}//output: name: LiYang

According to the page -> request - session - application order, the scope of the search, find that returns, eventually find returns null
Specify the scope:
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
| property scope of EL name |
| page ageScope, such as ${pageScope. Username} said in page scope for variable username and can't find the return null | | request requestScope |
| session sessionScope |
| application applicationScope |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --


EL expression syntax [6-3] :
For object attribute values: & lt; %=((User) request. GetAttribute (" User "). The getName () % & gt;
Point operator: ${user. The name}
The [] operator: ${user/" name "}

EL expression syntax [6-4] : from collection element List
//save the data in the Servlet or JSP
List names=new ArrayList ();
Names. The add (0, "LiYang");
Names. The add (1, "WangHua");
Request. SetAttribute (" names ", names);
//in the JSP to access data
Name: ${names [0]} & lt; br/>
Name: ${names [1]} & lt; br/> Use [] specified element subscript

EL expression syntax [6-5] : from collection element Map
//save the data in the Servlet or JSP
The Map names=new HashMap ();
Names. The put (" one ", "LiYang");
Names. The put (" two ", "WangHua");
Request. SetAttribute (" names ", names);
//in the JSP to access data
Name: ${names. One} & lt; br/> Using dot operator output
Name: ${names (" two ")} & lt; br/> Use the [] operator output

EL expression syntax [6-6] :
The expression:
1. The relational operator
2. The logical operators
3. The empty operator

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Relational operator instructions sample return results to true -
-==eq equals ${5==5} and ${5 eq 5} ${" a "==" a "} and ${" a "eq" a "}
--!=ne is not equal to ${23! 23 ne 5=5} and ${}
-- & lt; Lt is less than the ${3 & lt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related