net.hasor.web.controller
类 AbstractController

java.lang.Object
  继承者 net.hasor.web.controller.AbstractController

public abstract class AbstractController
extends Object

版本:
: 2013-8-14
作者:
赵永春 (zyc@hasor.net)

构造方法摘要
AbstractController()
           
 
方法摘要
 AbstractController addHeader(String key, String value)
          设置HttpServletResponseHeader属性
 net.hasor.core.AppContext getAppContext()
          Return AppContext.
<T> T
getAttr(String name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
 Integer getAttrForInt(String name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
 String getAttrForStr(String name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
 Enumeration<String> getAttrNames()
          Returns an Enumeration containing the names of the attributes available to this request.
 String getCookie(String name)
          Get cookie value by cookie name.
 String getCookie(String name, String defaultValue)
          Get cookie value by cookie name.
 javax.servlet.http.Cookie getCookieObject(String name)
          Get cookie object by cookie name.
 javax.servlet.http.Cookie[] getCookieObjects()
          Get all cookie objects.
 Integer getCookieToInt(String name)
          Get cookie value by cookie name and convert to Integer.
 Integer getCookieToInt(String name, Integer defaultValue)
          Get cookie value by cookie name and convert to Integer.
 Long getCookieToLong(String name)
          Get cookie value by cookie name and convert to Long.
 Long getCookieToLong(String name, Long defaultValue)
          Get cookie value by cookie name and convert to Long.
protected  Object getModel(Class<?> modelClass)
          Get model from AppContext.
protected  Object getModel(String modelName)
          Get model from AppContext.
 String getPara(String name)
          Returns the value of a request parameter as a String, or null if the parameter does not exist.
 String getPara(String name, String defaultValue)
          Returns the value of a request parameter as a String, or default value if the parameter does not exist.
 Map<String,String[]> getParaMap()
          Returns the values of the request parameters as a Map.
 Enumeration<String> getParaNames()
          Returns an Enumeration of String objects containing the names of the parameters contained in this request.
 Boolean getParaToBoolean(String name)
          Returns the value of a request parameter and convert to Boolean.
 Boolean getParaToBoolean(String name, Boolean defaultValue)
          Returns the value of a request parameter and convert to Boolean with a default value if it is null.
 Integer getParaToInt(String name)
          Returns the value of a request parameter and convert to Integer.
 Integer getParaToInt(String name, Integer defaultValue)
          Returns the value of a request parameter and convert to Integer with a default value if it is null.
 Long getParaToLong(String name)
          Returns the value of a request parameter and convert to Long.
 Long getParaToLong(String name, Long defaultValue)
          Returns the value of a request parameter and convert to Long with a default value if it is null.
 String[] getParaValues(String name)
          Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
 Integer[] getParaValuesToInt(String name)
          Returns an array of Integer objects containing all of the values the given request parameter has, or null if the parameter does not exist.
 javax.servlet.http.HttpServletRequest getRequest()
          Return HttpServletRequest.
 javax.servlet.http.HttpServletResponse getResponse()
          Return HttpServletResponse.
 javax.servlet.http.HttpSession getSession()
          Return HttpSession.
 javax.servlet.http.HttpSession getSession(boolean create)
          Return HttpSession.
<T> T
getSessionAttr(String key)
          Return a Object from session.
 void initController(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse)
           
 AbstractController putAtt(String attKey, Object attValue)
          设置HttpServletRequest属性
 AbstractController removeAttr(String name)
          Removes an attribute from this request
 AbstractController removeCookie(String name)
          Remove Cookie with path = "/".
 AbstractController removeCookie(String name, String path)
          Remove Cookie.
 AbstractController removeCookie(String name, String path, String domain)
          Remove Cookie.
 AbstractController removeSessionAttr(String key)
          Remove Object in session.
 void resetController()
           
 AbstractController setAttr(String name, Object value)
          Stores an attribute in this request
 AbstractController setAttrs(Map<String,Object> attrMap)
          Stores attributes in this request, key of the map as attribute name and value of the map as attribute value
 AbstractController setCookie(javax.servlet.http.Cookie cookie)
          Set Cookie to response.
 AbstractController setCookie(String name, String value, int maxAgeInSeconds)
          Set Cookie with path = "/".
 AbstractController setCookie(String name, String value, int maxAgeInSeconds, String path)
          Set Cookie to response.
 AbstractController setCookie(String name, String value, int maxAgeInSeconds, String path, String domain)
          Set Cookie to response.
 AbstractController setHeader(String key, String value)
          设置HttpServletResponseHeader属性
 AbstractController setSessionAttr(String key, Object value)
          Store Object to session.
 Integer toInt(String value, Integer defaultValue)
           
 Long toLong(String value, Long defaultValue)
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

AbstractController

public AbstractController()
方法详细信息

initController

public void initController(javax.servlet.http.HttpServletRequest httpRequest,
                           javax.servlet.http.HttpServletResponse httpResponse)

resetController

public void resetController()

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Return HttpServletRequest. Do not use HttpServletRequest Object in constructor of Controller


getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Return HttpServletResponse. Do not use HttpServletResponse Object in constructor of Controller


getAppContext

public net.hasor.core.AppContext getAppContext()
Return AppContext.


getSession

public javax.servlet.http.HttpSession getSession()
Return HttpSession.


getSession

public javax.servlet.http.HttpSession getSession(boolean create)
Return HttpSession.

参数:
create - a boolean specifying create HttpSession if it not exists

putAtt

public AbstractController putAtt(String attKey,
                                 Object attValue)
设置HttpServletRequest属性


setHeader

public AbstractController setHeader(String key,
                                    String value)
设置HttpServletResponseHeader属性


addHeader

public AbstractController addHeader(String key,
                                    String value)
设置HttpServletResponseHeader属性


setAttr

public AbstractController setAttr(String name,
                                  Object value)
Stores an attribute in this request

参数:
name - a String specifying the name of the attribute
value - the Object to be stored

removeAttr

public AbstractController removeAttr(String name)
Removes an attribute from this request

参数:
name - a String specifying the name of the attribute to remove

setAttrs

public AbstractController setAttrs(Map<String,Object> attrMap)
Stores attributes in this request, key of the map as attribute name and value of the map as attribute value

参数:
attrMap - key and value as attribute of the map to be stored

getPara

public String getPara(String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist.

You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use getParaValues(java.lang.String).

If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by getParameterValues.

参数:
name - a String specifying the name of the parameter
返回:
a String representing the single value of the parameter

getPara

public String getPara(String name,
                      String defaultValue)
Returns the value of a request parameter as a String, or default value if the parameter does not exist.

参数:
name - a String specifying the name of the parameter
defaultValue - a String value be returned when the value of parameter is null
返回:
a String representing the single value of the parameter

getParaMap

public Map<String,String[]> getParaMap()
Returns the values of the request parameters as a Map.

返回:
a Map contains all the parameters name and value

getParaNames

public Enumeration<String> getParaNames()
Returns an Enumeration of String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty Enumeration.

返回:
an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters

getParaValues

public String[] getParaValues(String name)
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist. If the parameter has a single value, the array has a length of 1.

参数:
name - a String containing the name of the parameter whose value is requested
返回:
an array of String objects containing the parameter's values

getParaValuesToInt

public Integer[] getParaValuesToInt(String name)
Returns an array of Integer objects containing all of the values the given request parameter has, or null if the parameter does not exist. If the parameter has a single value, the array has a length of 1.

参数:
name - a String containing the name of the parameter whose value is requested
返回:
an array of Integer objects containing the parameter's values

getAttrNames

public Enumeration<String> getAttrNames()
Returns an Enumeration containing the names of the attributes available to this request. This method returns an empty Enumeration if the request has no attributes available to it.

返回:
an Enumeration of strings containing the names of the request's attributes

getAttr

public <T> T getAttr(String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

参数:
name - a String specifying the name of the attribute
返回:
an Object containing the value of the attribute, or null if the attribute does not exist

getAttrForStr

public String getAttrForStr(String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

参数:
name - a String specifying the name of the attribute
返回:
an String Object containing the value of the attribute, or null if the attribute does not exist

getAttrForInt

public Integer getAttrForInt(String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

参数:
name - a String specifying the name of the attribute
返回:
an Integer Object containing the value of the attribute, or null if the attribute does not exist

toInt

public Integer toInt(String value,
                     Integer defaultValue)

getParaToInt

public Integer getParaToInt(String name)
Returns the value of a request parameter and convert to Integer.

参数:
name - a String specifying the name of the parameter
返回:
a Integer representing the single value of the parameter

getParaToInt

public Integer getParaToInt(String name,
                            Integer defaultValue)
Returns the value of a request parameter and convert to Integer with a default value if it is null.

参数:
name - a String specifying the name of the parameter
返回:
a Integer representing the single value of the parameter

toLong

public Long toLong(String value,
                   Long defaultValue)

getParaToLong

public Long getParaToLong(String name)
Returns the value of a request parameter and convert to Long.

参数:
name - a String specifying the name of the parameter
返回:
a Integer representing the single value of the parameter

getParaToLong

public Long getParaToLong(String name,
                          Long defaultValue)
Returns the value of a request parameter and convert to Long with a default value if it is null.

参数:
name - a String specifying the name of the parameter
返回:
a Integer representing the single value of the parameter

getParaToBoolean

public Boolean getParaToBoolean(String name)
Returns the value of a request parameter and convert to Boolean.

参数:
name - a String specifying the name of the parameter
返回:
false if the value of the parameter is "false" or "0", true if it is "true" or "1", null if parameter is not exists

getParaToBoolean

public Boolean getParaToBoolean(String name,
                                Boolean defaultValue)
Returns the value of a request parameter and convert to Boolean with a default value if it is null.

参数:
name - a String specifying the name of the parameter
返回:
false if the value of the parameter is "false" or "0", true if it is "true" or "1", default value if it is null

getSessionAttr

public <T> T getSessionAttr(String key)
Return a Object from session.

参数:
key - a String specifying the key of the Object stored in session

setSessionAttr

public AbstractController setSessionAttr(String key,
                                         Object value)
Store Object to session.

参数:
key - a String specifying the key of the Object stored in session
value - a Object specifying the value stored in session

removeSessionAttr

public AbstractController removeSessionAttr(String key)
Remove Object in session.

参数:
key - a String specifying the key of the Object stored in session

getCookie

public String getCookie(String name,
                        String defaultValue)
Get cookie value by cookie name.


getCookie

public String getCookie(String name)
Get cookie value by cookie name.


getCookieToInt

public Integer getCookieToInt(String name)
Get cookie value by cookie name and convert to Integer.


getCookieToInt

public Integer getCookieToInt(String name,
                              Integer defaultValue)
Get cookie value by cookie name and convert to Integer.


getCookieToLong

public Long getCookieToLong(String name)
Get cookie value by cookie name and convert to Long.


getCookieToLong

public Long getCookieToLong(String name,
                            Long defaultValue)
Get cookie value by cookie name and convert to Long.


getCookieObject

public javax.servlet.http.Cookie getCookieObject(String name)
Get cookie object by cookie name.


getCookieObjects

public javax.servlet.http.Cookie[] getCookieObjects()
Get all cookie objects.


setCookie

public AbstractController setCookie(javax.servlet.http.Cookie cookie)
Set Cookie to response.


setCookie

public AbstractController setCookie(String name,
                                    String value,
                                    int maxAgeInSeconds,
                                    String path)
Set Cookie to response.

参数:
name - cookie name
value - cookie value
maxAgeInSeconds - -1: clear cookie when close browser. 0: clear cookie immediately. n>0 : max age in n seconds.
path - see Cookie.setPath(String)

setCookie

public AbstractController setCookie(String name,
                                    String value,
                                    int maxAgeInSeconds,
                                    String path,
                                    String domain)
Set Cookie to response.

参数:
name - cookie name
value - cookie value
maxAgeInSeconds - -1: clear cookie when close browser. 0: clear cookie immediately. n>0 : max age in n seconds.
path - see Cookie.setPath(String)
domain - the domain name within which this cookie is visible; form is according to RFC 2109

setCookie

public AbstractController setCookie(String name,
                                    String value,
                                    int maxAgeInSeconds)
Set Cookie with path = "/".


removeCookie

public AbstractController removeCookie(String name)
Remove Cookie with path = "/".


removeCookie

public AbstractController removeCookie(String name,
                                       String path)
Remove Cookie.


removeCookie

public AbstractController removeCookie(String name,
                                       String path,
                                       String domain)
Remove Cookie.


getModel

protected Object getModel(Class<?> modelClass)
Get model from AppContext.


getModel

protected Object getModel(String modelName)
Get model from AppContext.



Copyright © 2013. All Rights Reserved.