JAVA J2EE front end

Architecture

BS (Broswer Server): Client through the browser can directly access the server
CS (Client Server): A
software upgrade if: So all the software needs to be upgraded
b maintenance problems: the need to maintain each client software
c each. a client need to install client software

Tomcat

Tomcat is a common free web server
environment configuration, service configuration, modify the port, the virtual path, virtual host, application configuration and deployment
occupied ports: netstat -ano | findstr "80" and taskkill / f / pid pin number
virtual path : the web project configuration to a directory other than webapps (conf / server.xml configured) (conf \ Catalina \ localhost in the new file and add virtual path) (web.xml in /: On behalf of the project root path http: / / localhost: 8888 / Servlet25Project /; jsp in /: server root path http: // localhost: 8888 /)
Hosting : implement native access via ip route before the domain name resolution

Jsp

Execution, page elements, the jump method, built-in objects, scope, JSTL, EL expression
execution process : (jsp- java (Servlet File) -class) first visit: the server will translate documents into jsp java, then java files compiled into class files, second visit: direct access to the class file (Jsp and Servlet interchangeable)
the Eclipse development : the browser can directly access the files in the WebContent, WEB-INF files can not be through the client (browser device) direct access can only be forwarded by requesting access, unified character set encoding, modify web.xml, configuration files, java code needs to restart the tomcat service, modify Jsp \ html \ css \ js, without rebooting.
page elements : HTML , java codes (script Scriptlet:! local and global variables, output = expression), command (page, language: jsp, import , pageEncoding: jsp, contentType), comment (html annotation, java annotation, jsp comments)
GET and POST : GET request mode in the address bar displays information (address information field but to accommodate limited, 4-5KB; request if there is a large data file, Films such as the address bar will not accommodate all of the data error); post does not display, upload the picture file must be a post
request forwarding and redirection :

Request forwarding Redirect
Address Bar constant change
Whether to retain the first request data Retention Not Retained
The number of requests 1 2
Jump occurrence location Server The client's second jump

cookie and the session : the same id

session cookie
Saved location Server Client
safety Safer Less secure
Save content object string

Scope :
Common methods: (Object getAttribute (String name) : The attribute name or attribute value), (void setAttribute (String name , Object obj): Set the attribute value (add, edit)) (setAttribute ( "a" , "b"); if there is not a subject before, create a new a target; if you have a previously exist, the value of a changed b) (void removeAttribute (String name ): according to the attribute name, delete the object)

Scope Object Types
pageContext The current page page objects
request With a valid request (request forwarding valid; Invalid redirect) Request Object
session At the same session is valid (in any case are valid jumps) Session object
application Globally valid (current valid project and during operation) Global Objects

Built-in objects :
OUT :( output object, outputting content to the client), Request (request object; stores "request information sent by the client to the server"), Response (response object, the main methods: increasing cookies, redirection, provided response code), session (session server) (cookie and server client session one correspondence) (session method) (cookie: equivalent to the role of local cache, cookie is not a built-in objects, you need new), application (global object ), config (configuration objects: server configuration object), page (current page object), exception (exception object), pageContext (jsp pages container)
JSP access the database : that is, the java JDBC code copied to the JSP <% ...%>
Jstl : use: introducing jar package, introducing tablib, c is a prefix
common tag library: (<c: set> can give general and map objects, variables, there is no variable assignment, but not to the object does not exist in the assignment ), (<c: out value = "">: (display data may not exist default)), (<c: remove>: delete Properties)
Condition tag library: single reselection (<c: if test = " ">) multi selector (<c: choose> + < c: when test = "">) ( using the test = "" must pay attention to the back whether spaces, spaces will become strings, i.e., non-true)
iteration tag library: <c: forEach items = " $ {...}" var = "" varStatus = "">

JavaBean : JSP code registered in the operation proceeds to class, to simplify the code, improve code reuse
use levels: encapsulate business logic, data encapsulation
a.public modified based, public constructor with no arguments
b all attributes (if any) are. private, and provides a set / get (boolean if you can get replaced iS)
the EL expression : in order to eliminate the jsp Java code syntax: $ {EL expression}, $ {requestScope object property attribute...} , in essence call calling get property method, using an operator: point or brackets (double quotes / single quotation marks, can accommodate special characters, variables and arrays), the Map key value, logical operators $ (3 > 2), empty operator, $ {empty. Object property}, implicit objects (pageScope, requestScope, sessionScope, applicationScope ), parameters of the object (form data, hyperlink data, the address field value data, $ {param}, $ {paramValues}), jsp built-in objects ($ {pageContext. removing method name () and get the first letter and lowercase}, cascading method)

Servlet

Coding : Chinese parameters of the problem (<meta http-equiv = " Content-Type" content = "text / html; charset = UTF-8">) (request.setCharacterEncoding ( "UTF-8");) (response.setContentType ( "text / html; charset = UTF -8");) encoding a (new String (parameter .getBytes ( "old coding"), a new coding) unified request;) URIEncoding get uniform encoding mode (in the server.xml = " UTF-8 ")
life cycle : load (single instantiation, execution time), initialization (executed once), service delivery, destruction, recycling unloading
Jump : forwards the request (request.getRequestDispatcher (" * .html ") forward (. request, response);), the redirection (response.sendRedirect ( "* .html") ;)
from the start : automatically initialize the correlation code: xml manner: (<load-on-startup > 1 </ load-on- startup>); 'annotation mode: (@ WebServlet (value = " / WelcomeServlet", loadOnStartup = 1))
to achieve : Java classes must meet certain specifications: must inherit javax.servlet.http.HttpServlet, wherein the rewriting doGet ( ) or doPost () method
steps : preparation of a class that inherits HttpServlet Rewrite doGet (), doPost () method; write web.
xml configuration : the root of the requested items are <servlet-mapping> in <url-pattern> to intercept, and find the corresponding class by name directory
Servlet3.0 Servlet2.5 with the differences :
Servlet3.0 need not web.xml configuration, but the need to write annotations @WebServlet ( "url-pattern of the value") of the above defined class Servlet
matching process: the request address value matches @WebServlet, if the matching is successful, then the request is the annotation corresponding class
API Detailed : method package (inheritance) and the HTTP protocol initialization parameter ServletContext class ServletConfig based interface; ServletResponse been converted and the ServletRequest HttpServletRequest and HttpServletResponse method, genericservlet is simple to make or empty the servlet achieve

MVC

M: Model Model: JavaBean implemented with a function
V: View view: html js css jsp jquery other front-end display technology, and a user interaction
C: Controller Controller: accept a request, the request for processing jumps to the model; Model Once processing is complete, then the results returned to the requesting process, the controller is implemented using Servlet

Three-tier architecture

MVN target design pattern the same, are coupled to understand and improve the rate of code reuse
with three layers: the presentation layer (the USL, view layer, and the front for interacting with a user interface display, in the WebContent (jsp, js, html , css, etc.), control jumps back to the business logic layer calls in Servlet package (SpringMVC, struts2)), business logic (the BLL, service layer, presentation layer requests received calls and data access layer assembly, in the service , manage, bll packet), the data access layer (the DAL, dao layer, the dao package)
the relationship between the three layers : an upper layer depends on the lower layer, the lower layer to the upper layer processing returns after
three optimization : added interface (recommended for interface development , x = new class that implements the interface () ;, Dao interfaces and service needs, the servlet required), using a common database DBUtil help simplify the class code amount Dao layer (implemented database connections, Update redundant code extraction operation)

Paging

5 variables: the total number of data, the page size, the total number of pages, this page, the current target page set
mysql substantially limit the implementation method : In general, the client by passing pageNo is not (page), the pageSize (per number of) two paged data parameter to query the database, use the built-in MySQL limit the amount of data is small to solve this problem and achieve a large number of data lines, primary keys and sort based on

File upload and download

File Upload : introducing components jar package, the form is submitted must post, add attributes entype as "multipart / form-data", note uploads directory due to recompile and failure, upload type and size limit
file downloads : not dependent jar package, jsp servlet request and the address by the file input stream into a file read seervlet, the file output by the output stream, in response to the need to provide two heads: (response.addHeader ( "content-Type ", "application / octet-stream" ) response.addHeader ( "content-Disposition" , "attachement; filename =" + fileName);) distortion when downloading files need to be set

filter

Filter : Filter interface implement a re-init () and destroy () principle, the filter configuration by the doFilter () process intercepted by chain.doFilter (request, response); release, between the primary and servlet jsp
wildcard
dispatcher request mode : request, forward, include, error
filter chain : the filter is determined by the order in <filter-mapping> position

Monitor

The Listen : listener objects that implement the interface (request (ServletRequestListener), session ( HttpSessionListener), application (ServletContextListener)), configure the listener
listens objects : Method: End monitor and start listening; ServletContext starts automatically created in the container; property changes :( realization request (ServletRequestAttributeListener), session (HttpSessionAttributeListener) , application (ServletContextAttributeListener) Interface) (respectively add, remove and replace method)
session unbind the passivation and activation : JavaWeb - binding solution tied session, the passivation activated ; JavaWeb-session activation passivation

Published 12 original articles · won praise 0 · Views 133

Guess you like

Origin blog.csdn.net/weixin_42142764/article/details/102494838