One, servlet declaration cycle
The 1.Servlet declaration cycle is generally divided into four steps: Load, instantiate, service, destroy.
2. Instantiation is performed only once throughout the life cycle.
Second, JSP
1.Servlet providing data to the JSP
Request.setattribute (,);
Example: Request.setattribute ("Key", "Hello");
2.Servlet Jump JSP
(1) Same request method: Request.getrequestdispatcher ("/path"). Forward (request, response);
The request jump can only be requested in the same way.
(2) Different request method: Response.sendredirect ("path");
The address bar will change after execution.
Write Java code in 3.jsp
(1) <%=%>
Can only write expressions, variable values
Example: <%= 1 + 1%>
<%= Request.getattribute ("Hello")%>
(2) <%
code block;
%>
Example: <%
String value = (string) request.getattribute ();
%>
4.HttpSession session = Request.getsession ();
Session.setattribute (,);
Can be under the same request, or under different requests, but in the same browser window.
Example: String value = (string) session.getattribute ("");
5.servletContext sc = Session.getservletcontext ();
Sc.setattribute (,);
You can also be under different browsers under the same request and at different requests.
String value = (string) application.getattribute ("");
Java Fundamentals Chapter 14th (servlet declaration cycle, Servlet provides data to JSP, servlet jump JSP, Java code written in JSP)