The Guice servlet provides several more useful web scopes, similar to those provided by the session,request of the traditional servlet.
The web scope provided by the Guice servlet is as follows:
[Email protected]
[Email protected]
[Email protected]
[Email protected]
Examples are as follows:
1 Packagecom.ming.user.action;2 3 Importcom.google.inject.servlet.RequestScoped;4 5 /**6 * Similar to the time we requested to save the value in this access7 * @authorMingge8 *9 */Ten @RequestScoped One Public classRequstscope { A - -}
1 Packagecom.ming.user.action;2 3 ImportCom.google.inject.Inject;4 ImportCom.google.inject.Provider;5 6 Public classRequstscopetest {7 8 @Inject9 PrivateProvider<requstscope> requst=NULL;Ten One ARequstscope A=requst.get ();//Use this method to fetch the value of this range - -}
[Email protected]
Examples are as follows:
1 Packagecom.ming.user.action;2 3 Importcom.google.inject.servlet.SessionScoped;4 5 @SessionScoped6 Public classSessionscope {7 8 Private intCount=0;9 Ten Public intGetCount () { One returncount; A } - - Public voidSetCount (intcount) { the This. Count =count; - } - - +}
1 Packagecom.ming.user.action;2 3 ImportCom.google.inject.Inject;4 ImportCom.google.inject.Provider;5 6 Public classSessionscopetest {7 8 @Inject9 PrivateProvider<sessionscope> session=NULL;Ten One ASessionscope A=session.get ();//Use this method to fetch the value of this range - - voidTest () { theA.setcount (2); - } -}
[Email protected]
Examples are as follows:
1 @Inject 2 @RequestParameters 3 Private Provider<map<string, string[]>> Reqparammapprovider;
Guice servlet is still relatively useful, if you choose to use the servlet to develop the proposal to use it.
Guice Basic use, Guice integration guice-servlet,web scope annotations (vi)