Top Description Inners Fields Constructors Methods
org.springframework.web.servlet

public abstract Class HttpServletBean

extends HttpServlet
implements EnvironmentCapable, EnvironmentAware
Class Inheritance
All Implemented Interfaces
org.springframework.context.EnvironmentAware, org.springframework.beans.factory.Aware, org.springframework.core.env.EnvironmentCapable
Known Direct Subclasses
org.springframework.web.servlet.FrameworkServlet
Annotations
@SuppressWarnings:serial
Imports
java.util.Enumeration, .HashSet, .Set, jakarta.servlet.ServletConfig, .ServletException, jakarta.servlet.http.HttpServlet, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.BeanWrapper, .BeansException, .MutablePropertyValues, .PropertyAccessorFactory, .PropertyValue, .PropertyValues, org.springframework.context.EnvironmentAware, org.springframework.core.env.ConfigurableEnvironment, .Environment, .EnvironmentCapable, org.springframework.core.io.Resource, .ResourceEditor, .ResourceLoader, org.springframework.lang.Nullable, org.springframework.util.Assert, .CollectionUtils, .StringUtils, org.springframework.web.context.support.ServletContextResourceLoader, .StandardServletEnvironment

Simple extension of jakarta.servlet.http.HttpServlet which treats its config parameters (init-param entries within the servlet tag in web.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 org.springframework.context.ApplicationContext concept. Simple servlets usually don't load their own context but rather access service beans from the Spring root application context, accessible via the filter's ServletContext (see org.springframework.web.context.support.WebApplicationContextUtils).

The FrameworkServlet class is a more specific servlet base class which loads its own application context. FrameworkServlet serves as direct base class of Spring's full-fledged DispatcherServlet.

Authors
Rod Johnson, Juergen Hoeller
See Also
addRequiredProperty, initServletBean, doGet, doPost

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
HttpServletBean.ServletConfigPropertyValues

PropertyValues implementation created from ServletConfig init parameters.

Field Summary

Modifier and TypeField and Description
private ConfigurableEnvironment
protected final Log
logger

Logger available to subclasses.

private final Set<String>
Inherited from jakarta.servlet.http.HttpServlet:
LEGACY_DO_HEAD

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected final void
addRequiredProperty(String
name of the required property
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 ConfigurableEnvironment
public ConfigurableEnvironment
public String
getServletName()

Overrides jakarta.servlet.GenericServlet.getServletName.

Implements jakarta.servlet.ServletConfig.getServletName.

Overridden method that simply returns null when no ServletConfig set yet.

public final void
init()

Overrides jakarta.servlet.GenericServlet.init.

Map config parameters onto bean properties of this servlet, and invoke subclass initialization.

protected void
initBeanWrapper(BeanWrapper
the BeanWrapper to initialize
bw
)

Initialize the BeanWrapper for this HttpServletBean, possibly with custom editors.

protected void
initServletBean()

Subclasses may override this to perform custom initialization.

public void
setEnvironment(Environment environment)

Implements org.springframework.context.EnvironmentAware.setEnvironment.

Set the Environment that this servlet runs in.

Any environment set here overrides the StandardServletEnvironment provided by default.

Inherited from jakarta.servlet.http.HttpServlet:
doDeletedoGetdoHeaddoOptionsdoPostdoPutdoTracegetLastModifiedinitserviceservice

Field Detail

environmentback to summary
private ConfigurableEnvironment environment
Annotations
@Nullable
loggerback to summary
protected final Log logger

Logger available to subclasses.

requiredPropertiesback to summary
private final Set<String> requiredProperties

Constructor Detail

HttpServletBeanback to summary
public HttpServletBean()

Method Detail

addRequiredPropertyback to summary
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.

Parameters
property:String

name of the required property

createEnvironmentback to summary
protected ConfigurableEnvironment createEnvironment()

Create and return a new StandardServletEnvironment.

Subclasses may override this in order to configure the environment or specialize the environment type returned.

getEnvironmentback to summary
public ConfigurableEnvironment getEnvironment()

Implements org.springframework.core.env.EnvironmentCapable.getEnvironment.

Return the Environment associated with this servlet.

If none specified, a default environment will be initialized via createEnvironment().

Annotations
@Override
getServletNameback to summary
public String getServletName()

Overrides jakarta.servlet.GenericServlet.getServletName.

Implements jakarta.servlet.ServletConfig.getServletName.

Overridden method that simply returns null when no ServletConfig set yet.

Returns:String

Doc from jakarta.servlet.GenericServlet.getServletName.

the name of this servlet instance

Annotations
@Override
@Nullable
See Also
getServletConfig()
initback to summary
public final void init() throws ServletException

Overrides jakarta.servlet.GenericServlet.init.

Map config parameters onto bean properties of this servlet, and invoke subclass initialization.

Annotations
@Override
Exceptions
ServletException:
if bean properties are invalid (or required properties are missing), or if subclass initialization fails.
initBeanWrapperback to summary
protected void initBeanWrapper(BeanWrapper bw) throws BeansException

Initialize the BeanWrapper for this HttpServletBean, possibly with custom editors.

This default implementation is empty.

Parameters
bw:BeanWrapper

the BeanWrapper to initialize

Exceptions
BeansException:
if thrown by BeanWrapper methods
See Also
org.springframework.beans.BeanWrapper#registerCustomEditor
initServletBeanback to summary
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.

Exceptions
ServletException:
if subclass initialization fails
setEnvironmentback to summary
public void setEnvironment(Environment environment)

Implements org.springframework.context.EnvironmentAware.setEnvironment.

Set the Environment that this servlet runs in.

Any environment set here overrides the StandardServletEnvironment provided by default.

Annotations
@Override
Exceptions
IllegalArgumentException:
if environment is not assignable to ConfigurableEnvironment
org.springframework.web.servlet back to summary

private Class HttpServletBean.ServletConfigPropertyValues

extends MutablePropertyValues
Class Inheritance

PropertyValues implementation created from ServletConfig init parameters.

Constructor Summary

AccessConstructor and Description
public
ServletConfigPropertyValues(ServletConfig
the ServletConfig we'll use to take PropertyValues from
config
,
Set<String>
set of property names we need, where we can't accept default values
requiredProperties
)

Create new ServletConfigPropertyValues.

Method Summary

Inherited from org.springframework.beans.MutablePropertyValues:
addaddPropertyValueaddPropertyValueaddPropertyValuesaddPropertyValueschangesSinceclearProcessedPropertycontainsequalsgetgetPropertyValuegetPropertyValueListgetPropertyValueshashCodeisConvertedisEmptyiteratorregisterProcessedPropertyremovePropertyValueremovePropertyValuesetConvertedsetPropertyValueAtsizespliteratorstreamtoString

Constructor Detail

ServletConfigPropertyValuesback to summary
public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties) throws ServletException

Create new ServletConfigPropertyValues.

Parameters
config:ServletConfig

the ServletConfig we'll use to take PropertyValues from

requiredProperties:Set<String>

set of property names we need, where we can't accept default values

Exceptions
ServletException:
if any required properties are missing