nearly one months did not see the servlet, coupled with the first study did not go into, just a general look over, made up a bit of the basic case has passed, and now go to see the feeling and did not learn the same. Here again with a little time to comb these basics, deepen the impression and prepare for a quick review, after all, this is a fast-paced society, everything to quickly do the groundwork.
First, make it clear that the basic servlet programming role is assumed in enterprise applications. If you do not consider using other frameworks to develop, I think the implementation of the MVC Architecture Division should be M:javabean, v:jsp, C:servlet. As a special servlet. JSP because of its own characteristics, acting as the responsible collection of user requests, presenting data to the user, intermediate data processing links to the servlet processing.
This article is to tidy up some scattered knowledge points.
Well, get into the Special foundation section: Getting Started with JSP Basics:
comments and declarations:
<!--HTML comment-->//on the page to view the source code display <%--jsp comments--%>//<span style= "font-family:arial, Helvetica, Sans-serif;" > on the page to view the source code does not display </span><%! JSP declaration int i;%><% out.println (i++)%><table bgcolor= "#9999dd" border= "1" width= "300px" ><% for (int i=0;i<5;i++) {%> <tr><td> <%=i%> lines </td> <td>hello</td></tr> <% }%>
three compiler directives for JSP:
- Page
Define some of the property issues on this page. For example:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "
Here, if there is an error page, you need to set the error page erorpage= "error.jsp" iserrorpage= "true" in error.jsp.
- Include: include other pages dynamically
<jsp:include page= "/index.jsp" > <jsp:param value= "123" Name= "key"/></jsp:include>
- Taglib: Label
Define the labels used in the page: for example
<%@ taglib prefix= "s" uri= "/struts-tags"%>
JSP nine built-in objects:
This is mainly about Application+session+request+response. Where application is within the scope of the entire project, the session scope is a user session, and request is a user demand. Here is an example of setting the properties of three scopes:
<% Application.setattribute ("Key1", "Hello"); Session.setattribute ("Key2", "Hello"); Request.setattribute ("Key3", "Hello");%>
Since this is response, let's talk about forwarding and redirection. Forwarding is the same request, the properties within the request can be valid, and the page URL will not change. 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 a beginning, a brief introduction of the JSP several knowledge points, the following is written in the servlet section.
Servlet Basics Grooming (I.)