Servlet BASICS (1): servlet Basics
I haven't looked at servlet for nearly a month, and I haven't gone deep into my first study. I just read it all in a general sense. After compiling some basic cases, I feel like I have never learned it. Here, I will take a moment to sort out these foundations, deepen my impressions and prepare for future quick review. After all, this is a fast-paced society, and everything is quickly paved the way.
First, it is clear that the basic servlet programming plays a role in enterprise applications. If you do not consider using other frameworks for development, I think the division of labor for implementing the MVC Architecture should be M: javaBean, V: jsp, C: servlet. As a special servlet. Due to its own characteristics, jsp acts as responsible for collecting user requests and presenting data to users. The intermediate data processing process is handed over to servlet for processing.
This article organizes some scattered knowledge points.
Now, go to the special basics section: JSP basics:
Comments and declarations:
<! -- HTML comment --> // view the source code display on the page <% -- Jsp comment -- %> // <span style = "font-family: Arial, Helvetica, sans-serif; "> the source code is not displayed on the page </span> <%! // Declare int I; %> <% out. println (I ++); %> <table bgcolor = "# 9999dd" border = "1" width = "300px"> <% for (int I = 0; I <5; I ++) {%> <tr> <td> row <% = I %> </td> <td> hello </td> </tr> <%} %>
Three jsp compilation commands:
Nine built-in jsp objects:
Here we mainly talk about application + session + request + response. The application is within the entire project, the session is a user session, and the request is a user request. The following example sets the attributes of three ranges:
<% application.setAttribute("key1", "hello"); session.setAttribute("key2", "hello"); request.setAttribute("key3", "hello");%>
Now that response is involved, let's talk about forwarding and redirection. Forwarding is the same request. The attributes in the request are valid and the page url is not changed. Redirection is a new user request, and the URL changes. Basic implementation code:
request.getRequestDispatcher("login.jsp").forward(request, response); response.sendRedirect("login.jsp");
OK. This is an opening section. It briefly introduces several knowledge points of jsp. The servlet section is written below.