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:
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.