类 HttpServletBean
- java.lang.Object
- javax.servlet.GenericServlet
- javax.servlet.http.HttpServlet
- org.springframework.web.servlet.HttpServletBean
- 所有已实现的接口:
Serializable,Servlet,ServletConfig,Aware,EnvironmentAware,EnvironmentCapable
- 直接已知子类:
FrameworkServlet
public abstract class HttpServletBean extends HttpServlet implements EnvironmentCapable, EnvironmentAware
Simple extension ofHttpServletwhich treats its config parameters (init-paramentries within theservlettag inweb.xml) as bean properties.A handy superclass for any type of servlet. Type conversion of config parameters is automatic, with the corresponding setter method getting invoked with the converted value. It is also possible for subclasses to specify required properties. Parameters without matching bean property setter will simply be ignored.
This servlet leaves request handling to subclasses, inheriting the default behavior of HttpServlet (
doGet,doPost, etc).This generic servlet base class has no dependency on the Spring
ApplicationContextconcept. Simple servlets usually don't load their own context but rather access service beans from the Spring root application context, accessible via the filter'sServletContext(seeWebApplicationContextUtils).The
FrameworkServletclass is a more specific servlet base class which loads its own application context. FrameworkServlet serves as direct base class of Spring's full-fledgedDispatcherServlet.
构造器概要
构造器 构造器 说明 HttpServletBean()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected voidaddRequiredProperty(String property)Subclasses can invoke this method to specify that this property (which must match a JavaBean property they expose) is mandatory, and must be supplied as a config parameter.protected ConfigurableEnvironmentcreateEnvironment()Create and return a newStandardServletEnvironment.ConfigurableEnvironmentgetEnvironment()Return theEnvironmentassociated with this servlet.StringgetServletName()Overridden method that simply returnsnullwhen no ServletConfig set yet.voidinit()Map config parameters onto bean properties of this servlet, and invoke subclass initialization.protected voidinitBeanWrapper(BeanWrapper bw)Initialize the BeanWrapper for this HttpServletBean, possibly with custom editors.protected voidinitServletBean()Subclasses may override this to perform custom initialization.voidsetEnvironment(Environment environment)Set theEnvironmentthat this servlet runs in.从类继承的方法 javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
从类继承的方法 javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, init, log, log
构造器详细资料
HttpServletBean
public HttpServletBean()
方法详细资料
addRequiredProperty
protected final void addRequiredProperty(String property)
Subclasses can invoke this method to specify that this property (which must match a JavaBean property they expose) is mandatory, and must be supplied as a config parameter. This should be called from the constructor of a subclass.This method is only relevant in case of traditional initialization driven by a ServletConfig instance.
- 参数:
property- name of the required property
setEnvironment
public void setEnvironment(Environment environment)
Set theEnvironmentthat this servlet runs in.Any environment set here overrides the
StandardServletEnvironmentprovided by default.- 指定者:
setEnvironment在接口中EnvironmentAware- 抛出:
IllegalArgumentException- if environment is not assignable toConfigurableEnvironment
getEnvironment
public ConfigurableEnvironment getEnvironment()
Return theEnvironmentassociated with this servlet.If none specified, a default environment will be initialized via
createEnvironment().- 指定者:
getEnvironment在接口中EnvironmentCapable
createEnvironment
protected ConfigurableEnvironment createEnvironment()
Create and return a newStandardServletEnvironment.Subclasses may override this in order to configure the environment or specialize the environment type returned.
init
public final void init() throws ServletException
Map config parameters onto bean properties of this servlet, and invoke subclass initialization.- 覆盖:
init在类中GenericServlet- 抛出:
ServletException- if bean properties are invalid (or required properties are missing), or if subclass initialization fails.
initBeanWrapper
protected void initBeanWrapper(BeanWrapper bw) throws BeansException
Initialize the BeanWrapper for this HttpServletBean, possibly with custom editors.This default implementation is empty.
- 参数:
bw- the BeanWrapper to initialize- 抛出:
BeansException- if thrown by BeanWrapper methods- 另请参阅:
PropertyEditorRegistry.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
initServletBean
protected void initServletBean() throws ServletException
Subclasses may override this to perform custom initialization. All bean properties of this servlet will have been set before this method is invoked.This default implementation is empty.
- 抛出:
ServletException- if subclass initialization fails
getServletName
@Nullable public String getServletName()
Overridden method that simply returnsnullwhen no ServletConfig set yet.- 指定者:
getServletName在接口中ServletConfig- 覆盖:
getServletName在类中GenericServlet- 返回:
- the name of this servlet instance
- 另请参阅:
GenericServlet.getServletConfig()