Spring comes with JPETSTORE analysis (1)

xiaoxiao2021-03-06  13

Spring MVC Spring Ibatis or Struts MVC Spring iBATIS uses Spring combo, and the example given by iBatis is different from ================ installation: The environment I use is mysql. After compiling the WAR file according to Readme, the Tomcat4 creates a database table and inserts data according to two files. It will find that there is no thing below Web-INF, in fact, all servlets are packaged to JPETStore. Jar is in it. For the trial, I removed this JAR package and recompiled it with Eclipse. -------------- Use Spring comes with JPETStore, MVC uses two, Spring and Struts, the default MVC framework is Spring. If you want to use struts, configure web.xml, change the * .do mapping to Struts ActionServlet (changed to the partial part of the comment) The data persistence layer is iBATIS.

Note that all JSP pages are placed under Web-INF, access through servlet, so you can't directly access JSP pages directly through the address, improve security. First analyze the part of the Struts MVC. The index.html homepage gives links to Shop / INDEX.DO. Struts-config.xml where DonotionGAction returns an ActionForward object SUCCESS. Why not directly ? It may be a question that considers the standard format. (Test, this way no problem)

The following is based on the process from the Access Home to Login to complete the specific process. (Using Struts's MVC frame) ==== index.jsp === TAGLIB JSTL. The page consists of 4 parts, including includetop.jsp, this page, includebanner.jsp, includebottom.jsp. Use Taglib to get user data in the session in the includetop.jsp.jsp. Depending on whether there is data to display the corresponding content. === Signonform.jsp === Login is available in includetop.jsp, defined as shown below is also a jump directly access JSP. Signonform.jsp is a form

" method = "post"> configuration === SignonAction === This SignonAction inherits the baseAction This servlet has a function that if the link comes with parameter SIGNOFF, you can log out, that is, get the session invalid from the ActionForm Account = getPetStore. ) .Getaccount (username, password); this row statement is to obtain account information, here starting to use Spring and Bo (Business Object). If there is no Account returns, Request.setttribute ("Message", "INVALID Username or password. Signon failed."); And find Forward "failure", it should be the global forward Create a new AccountActionForm Accountform and store it in the session. Return to the home page or the Forward in Form.

(Forward in FORM is not logged in or permissions, save the current path, prompt login, get the page after logging in to return the page, for example: Enter shop / editaccountform.do in the address bar without logging in, will Turn to the login page, automatically return Shop / EditaccountForm.do after logging in. This feature is controlled by the public abstract class securebaseaction extends baseAction, verification of permissions in the Execute method in this action) --------- ------ GetPetStore () is defined in the baseAction, returns an org.springframework.samples.jpetstore.domain.logic.petstoreFacade, which is an interface. Define private petstorefacade petstore in baseAction; followed by a public void setservlet (ActionServlet ActionServlet), which is overloaded, and Struts automatically performs this method when creating an Action instance. (See struts api doc) (there is a problem, I do not know whether this petStore is thread-safe.) SetServlet to get PetStoreFacade corresponding implementation ServletContext servletContext = actionServlet.getServletContext by spring (); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext (servletContext); THIS.PETSTORE = (PetStoreFacade) Wac.getBean ("PetStore"); to initialize PetStore.

转载请注明原文地址:https://www.9cbs.com/read-51055.html

New Post(0)