Spring MVC Model Running Series Analysis

xiaoxiao2021-03-06  51

1) Assuming that your request is http: // localhost: 8080 / springapp / index.jsp2) To securely consider, in Index.jsp generally request the redirect to the web-inferry: 3) In Web.xml, send the request for * .htm to org.springframework.web.servlet.dispatcherservlets:

springapp org.springframework.web.servlet.dispatcherservlet 1

springapp *. htm 4) org.springframework.web.servlet.dispatcherServlet will get The current application name APRINGAPP, and automatically finds and resolves the springapp-servlet.xml file. 5) ForwardApp-servlet.xml files, forward the /Hello.htm to the SpringAppController springappController 6) in springapp-servlet.xml file, class files corresponding to the configuration springappController 7) Implement your own controller Web.SpringAppController, for example: Package Web;

Import Org.SpringFramework.Web.Servlet.mvc.controller; import org.springframework.web.servlet.modelandView;

Import javax.servlet.servletException; import javax.servlet.http.httpservletRequest; import javax.servlet.http.httpservletResponse;

Import java.io.ioException; import java.util.map; import java.util.hashmap; import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory;

Import Bus.Product; Import Bus.ProductManager;

Public Class SpringAppController Implements Controller {

/ ** logger for this class and subclasses * / protected final log logger = logfactory.getlog (getclass ());

Private productManager product;

Public ModlandView HandleRequest (httpservletRequest Request, httpservletResponse response) throws servletexception, ioException {

String now = (new java.util.date ()). Tostring (); logger.info ("Returning Hello View with" now);

Map mymodel = new hashmap (); mymodel.put ("now", now); MyModel.put ("products", getProductManager (). GetProducts ());

Return New ModelandView ("Hello", "Model", MyModel;

Public Void SetProductManager (ProductManager PM) {productMan = PM;}

Public productManager getProductManager () {return product ()} Note, type 2 mode of IOC mode in the controller. 8) There are three parameters, the first is the name of the next view, the second is Model Object Alias, the third is the Model Object object, and the latter two parameters will be used in the next view.

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

New Post(0)