Environment context object (WebContext)
In order to allow developers to obtain and use Web container objects such as Request, Response, and Session anytime and anywhere, the YMP framework provides a Web environment context encapsulation class called WebContext in the WebMVC module. It is simple and practical. First, Learn about the methods provided:
Get the Web container object directly:
Get the WebMVC container object:
Get the ServletContext object:
WebContext.getServletContext();Get the HttpServletRequest object:
WebContext.getRequest();- ##Get the HttpServletResponse object:
WebContext.getResponse();- Get the PageContext object:
WebContext.getPageContext();
- Get the IRequestContext object:
WebContext.getRequestContext();WebMVC request context interface, mainly used to analyze the request path and store related parameters;
- Get the WebContext object instance:
WebContext.getContext();WebContext converts the properties of Web container objects such as Application, Session, and Request into Map mapping storage. At the same time, the assignment to Map will also be automatically synchronized to the Web container object of the object. Initially, The purpose is to facilitate code transplantation and develop and test without dependency on the Web environment (for functions, please refer to Struts2):
WebContext Auxiliary method for operating Application:
WebContext.getContext().getApplication();
WebContext.getContext().getSession();
WebContext.getContext().getAttribute(Type.Context.REQUEST);
Originally it could be obtained directly through the WebContext.getContext().getRequest method, but due to a design error, the method name has been occupied by WebContext.getRequest(). If the method name is changed, the affected There are too many projects, so I have to deal with it :D. More auxiliary methods will be introduced later to operate the Request attribute, so you can ignore its existence!
- ##WebContext.getContext().getAttributes();
- WebContext.getContext().getLocale();
- WebContext.getContext().getOwner();
- WebContext.getContext().getParameters();
WebContext Auxiliary method for operating Session:
- boolean getApplicationAttributeToBoolean(String name);
- int getApplicationAttributeToInt( String name);
- long getApplicationAttributeToLong(String name);
- String getApplicationAttributeToString(String name);
- <T> T getApplicationAttributeToObject(String name);
- WebContext addApplicationAttribute(String name, Object value)
WebContext operation Request Auxiliary methods:
- boolean getSessionAttributeToBoolean(String name);
- int getSessionAttributeToInt(String name);
- long getSessionAttributeToLong(String name);
##String getSessionAttributeToString(String name);- < ;T> T getSessionAttributeToObject(String name);
- WebContext addSessionAttribute(String name, Object value)
boolean getParameterToBoolean(String name);boolean getRequestAttributeToBoolean(String name);
- int getRequestAttributeToInt(String name);
- long getRequestAttributeToLong(String name);
- String getRequestAttributeToString(String name);
- ##<T> T getRequestAttributeToObject (String name);
- WebContext addRequestAttribute(String name, Object value)
- ##WebContext auxiliary method for operating Parameter:
int getParameterToInt(String name)
long getParameterToLong(String name);
String getParameterToString(String name);
- WebContext auxiliary method for operating Attribute:
<T> T getAttribute(String name);
WebContext addAttribute(String name, Object value);
WebContext获取IUploadFileWrapper上传文件包装器:
IUploadFileWrapper getUploadFile(String name);
IUploadFileWrapper[] getUploadFiles(String name);