l PriceInCReaseForm bean defines the controller corresponding to the form:
Ø Sessionform: Whether to enable session
Ø CommandName: Command object name, reference in the Spring tag
Ø CommistClass: Class full path for Command object
Ø Validator: Verifier class full path
Ø Formview: Table View Page
Ø SUCCESSVIEW: The view page displayed after the form is submitted (the translator: the logical name cannot be used)
l Form Controller Extension SimpleFormController, the main process is an onSubmit () method, its parameter is the specified Command object to get the data submitted by the form, then call the ProductManager's increaseprice () method to increase the price, and finally redirect to SuccessView
Package web;
Import org.springframework.web.servlet.mvc.simpleformController;
Import org.springframework.Web.Servlet.ModelandView;
Import Org.SpringFramework.Web.Servlet.View.RedirectView;
Import javax.servlet.servletException;
Import javax.servlet.http.httpservletRequest;
Import java.util.map;
Import java.util.hashmap;
Import org.apache.commons.logging.log;
Import org.apache.commons.logging.logfactory;
Import Bus.ProductManager;
Import bus.priceincrease;
Public Class PriceIncreaseformController Extends SimpleFormController {
/ ** Logger for this class and subclasses * /
Protected final log logger = logfactory.getlog (getclass ());
Private productManager product;
Public ModilandView OnSubmit (Object Command)
Throws servletexception {
INT INCREASE = (PriceInCrease) Command .GetPercentage ();
Logger.info ("Increase PriceS By" Increase "%.");
Prodman.Increaseprice (Increase);
String now = (New java.util.date ()). TOSTRING ();
Logger.info ("Returning from PriceIncreaseform View TO" GetSuccessView ()
"$ now);
Map mymodel = new hashmap ();
MyModel.Put ("now", now);
MyModel.put ("Products", getProductManager (). getProducts ()); return new modelAndview (new redirectView (getSuccessView ());
}
Protected Object FormBackingObject (httpservletRequest Request) throws servletexception {
PriceIncrease priceIncrease = new priceIncrease ();
PriceinCrease.setpercentage (20);
Return PriceinCrease;
}
Public Void SetProductManager (ProductManager PM) {
PRODMAN = PM;
}
Public productManager getProductManager () {
Return Prodman
}
}
l formBackingObject () method is back to the data to the form, and finally returns a Command object.
l In Messages.properties, add some messages used in this case:
Title = SpringApp
Heading = hello :: SpringApp
Greeting = Greetings, IT IS NOW
PriceinCrease.Heading = Price Increase :: SpringApp
Error.Not-Specified = Percentage Not Specified !!!
Error.Too-low = you have to specify a percentage higher Than {0}!
Error.Too-high = don't be greedy - you can't raise price by more more {0}%!
REQUIRED = Entry Required.
TypeMatch = INVALID DATA.
TypeMatch.Percentage = That is not a number !!!
l At the same time, add the link to the priceIncrease.jsp from Hello.jsp.
<% @ include file = "/ web-inf / jsp / incrude.jsp"%>
p>
c: Foreach>
body>
html>
l Re-deploy the program, you can test your program.