actionservlet.java
来自「这是一个轻便的j2ee的web应用框架,是一个在多个项目中运用的实际框架,采用s」· Java 代码 · 共 1,671 行 · 第 1/5 页
JAVA
1,671 行
* The flag to request backwards-compatible conversions for form bean
* properties of the Java wrapper class types.
* @since Struts 1.1
*/
protected boolean convertNull = false;
/**
* The JDBC data sources that has been configured for this module,
* if any, keyed by the servlet context attribute under which they are
* stored.
*/
protected FastHashMap dataSources = new FastHashMap();
/**
* The debugging detail level for this servlet.
* @deprecated
*/
protected int debug = 0;
/**
* The resources object for our internal resources.
*/
protected MessageResources internal = null;
/**
* The Java base name of our internal resources.
* @since Struts 1.1
*/
protected String internalName = "org.apache.struts.action.ActionResources";
/**
* Commons Logging instance.
* @since Struts 1.1
*/
protected static Log log = LogFactory.getLog(ActionServlet.class);
/**
* The <code>RequestProcessor</code> instance we will use to process
* all incoming requests.
* @since Struts 1.1
*/
protected RequestProcessor processor = null;
/**
* The set of public identifiers, and corresponding resource names, for
* the versions of the configuration file DTDs that we know about. There
* <strong>MUST</strong> be an even number of Strings in this list!
*/
protected String registrations[] = {
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN",
"/org/apache/struts/resources/struts-config_1_0.dtd",
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN",
"/org/apache/struts/resources/struts-config_1_1.dtd",
"-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
"/org/apache/struts/resources/web-app_2_2.dtd",
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
"/org/apache/struts/resources/web-app_2_3.dtd"
};
/**
* The URL pattern to which we are mapped in our web application
* deployment descriptor. FIXME - multiples???
*/
protected String servletMapping = null;
/**
* The servlet name under which we are registered in our web application
* deployment descriptor.
*/
protected String servletName = null;
// ---------------------------------------------------- HttpServlet Methods
/**
* Gracefully shut down this controller servlet, releasing any resources
* that were allocated at initialization.
*/
public void destroy() {
if (log.isDebugEnabled()) {
log.debug(internal.getMessage("finalizing"));
}
destroyModules();
destroyDataSources();
destroyInternal();
getServletContext().removeAttribute(Globals.ACTION_SERVLET_KEY);
// FIXME - destroy ModuleConfig and message resource instances
// Release our LogFactory and Log instances (if any)
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = ActionServlet.class.getClassLoader();
}
try {
LogFactory.release(classLoader);
} catch (Throwable t) {
; // Servlet container doesn't have the latest version
; // of commons-logging-api.jar installed
// FIXME Why is this dependent on the container's version of commons-logging?
// Shouldn't this depend on the version packaged with Struts?
}
}
/**
* Initialize this servlet. Most of the processing has been factored into
* support methods so that you can override particular functionality at a
* fairly granular level.
*
* @exception ServletException if we cannot configure ourselves correctly
*/
public void init() throws ServletException {
initInternal();
initOther();
initServlet();
// Initialize modules as needed
getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
ModuleConfig moduleConfig = initModuleConfig("", config);
initModuleMessageResources(moduleConfig);
initModuleDataSources(moduleConfig);
initModulePlugIns(moduleConfig);
moduleConfig.freeze();
Enumeration names = getServletConfig().getInitParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (!name.startsWith("config/")) {
continue;
}
String prefix = name.substring(6);
moduleConfig = initModuleConfig
(prefix, getServletConfig().getInitParameter(name));
initModuleMessageResources(moduleConfig);
initModuleDataSources(moduleConfig);
initModulePlugIns(moduleConfig);
moduleConfig.freeze();
}
destroyConfigDigester();
}
/**
* Process an HTTP "GET" request.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
process(request, response);
}
/**
* Process an HTTP "POST" request.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
process(request, response);
}
// --------------------------------------------------------- Public Methods
/**
* Remember a servlet mapping from our web application deployment
* descriptor, if it is for this servlet.
*
* @param servletName The name of the servlet being mapped
* @param urlPattern The URL pattern to which this servlet is mapped
*/
public void addServletMapping(String servletName, String urlPattern) {
if (log.isDebugEnabled()) {
log.debug("Process servletName=" + servletName +
", urlPattern=" + urlPattern);
}
if (servletName == null) {
return;
}
if (servletName.equals(this.servletName)) {
this.servletMapping = urlPattern;
}
}
/**
* Return a JDBC data source associated with this module, if any.
*
* @param key The servlet context attribute key under which this data
* source is stored, or <code>null</code> for the default.
*
* @deprecated Look up data sources directly in servlet context attributes
*/
public DataSource findDataSource(String key) {
if (key == null) {
return ((DataSource) dataSources.get(Globals.DATA_SOURCE_KEY));
} else {
return ((DataSource) dataSources.get(key));
}
}
/**
* Return the form bean definition associated with the specified
* logical name, if any; otherwise return <code>null</code>.
*
* @param name Logical name of the requested form bean definition
*
* @deprecated Replaced by ModuleConfig.findFormBeanConfig()
*/
public ActionFormBean findFormBean(String name) {
ActionFormBeans afb = (ActionFormBeans)
getServletContext().getAttribute(Globals.FORM_BEANS_KEY);
if (afb == null) {
return (null);
}
return (afb.findFormBean(name));
}
/**
* Return the forwarding associated with the specified logical name,
* if any; otherwise return <code>null</code>.
*
* @param name Logical name of the requested forwarding
*
* @deprecated Replaced by ModuleConfig.findForwardConfig()
*/
public ActionForward findForward(String name) {
ActionForwards af = (ActionForwards)
getServletContext().getAttribute(Globals.FORWARDS_KEY);
if (af == null) {
return (null);
}
return (af.findForward(name));
}
/**
* Return the ActionMapping for the specified path, for the default
* module.
*
* @param path Request path for which a mapping is requested
*
* @deprecated Replaced by ModuleConfig.findActionConfig()
*/
public ActionMapping findMapping(String path) {
ActionMappings am = (ActionMappings)
getServletContext().getAttribute(Globals.MAPPINGS_KEY);
if (am == null) {
return (null);
}
return (am.findMapping(path));
}
/**
* Return the debugging detail level for this servlet.
*
* @deprecated Configure the logging detail level in your underlying
* logging implementation
*/
public int getDebug() {
return (this.debug);
}
/**
* Return the <code>MessageResources</code> instance containing our
* internal message strings.
* @since Struts 1.1
*/
public MessageResources getInternal() {
return (this.internal);
}
/**
* <p>Return the application resources for the default module,
* if any.
*
* @deprecated Actions should call Action.getResources(HttpServletRequest)
* instead of this method, in order to retrieve the resources for the
* current module.
*/
public MessageResources getResources() {
return ((MessageResources) getServletContext().getAttribute
(Globals.MESSAGES_KEY));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?