📄 actionservlet.java
字号:
* Initialize other global characteristics of the controller servlet.
*
* @exception ServletException if we cannot initialize these resources
*/
protected void initOther() throws ServletException {
String value = null;
value = getServletConfig().getInitParameter("config");
if (value != null) {
config = value;
}
value = getServletConfig().getInitParameter("debug");
if (value != null) {
try {
debug = Integer.parseInt(value);
} catch (NumberFormatException e) {
// FIXME Why should we catch this? If the programmer has specified an
// invalid integer we should probably let this RuntimeException bubble up.
debug = 0;
}
}
// Backwards compatibility for form beans of Java wrapper classes
// Set to true for strict Struts 1.0 compatibility
value = getServletConfig().getInitParameter("convertNull");
if ("true".equalsIgnoreCase(value)
|| "yes".equalsIgnoreCase(value)
|| "on".equalsIgnoreCase(value)
|| "y".equalsIgnoreCase(value)
|| "1".equalsIgnoreCase(value)) {
convertNull = true;
}
if (convertNull) {
ConvertUtils.deregister();
ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class);
ConvertUtils.register(new BooleanConverter(null), Boolean.class);
ConvertUtils.register(new ByteConverter(null), Byte.class);
ConvertUtils.register(new CharacterConverter(null), Character.class);
ConvertUtils.register(new DoubleConverter(null), Double.class);
ConvertUtils.register(new FloatConverter(null), Float.class);
ConvertUtils.register(new IntegerConverter(null), Integer.class);
ConvertUtils.register(new LongConverter(null), Long.class);
ConvertUtils.register(new ShortConverter(null), Short.class);
}
}
/**
* Initialize the servlet mapping under which our controller servlet
* is being accessed. This will be used in the <code>&html:form></code>
* tag to generate correct destination URLs for form submissions.
* @throws ServletException if error happens while scanning web.xml
*/
protected void initServlet() throws ServletException {
// Remember our servlet name
this.servletName = getServletConfig().getServletName();
// Prepare a Digester to scan the web application deployment descriptor
Digester digester = new Digester();
digester.push(this);
digester.setNamespaceAware(true);
digester.setValidating(false);
// Register our local copy of the DTDs that we can find
for (int i = 0; i < registrations.length; i += 2) {
URL url = this.getClass().getResource(registrations[i+1]);
if (url != null) {
digester.register(registrations[i], url.toString());
}
}
// Configure the processing rules that we need
digester.addCallMethod("web-app/servlet-mapping",
"addServletMapping", 2);
digester.addCallParam("web-app/servlet-mapping/servlet-name", 0);
digester.addCallParam("web-app/servlet-mapping/url-pattern", 1);
// Process the web application deployment descriptor
if (log.isDebugEnabled()) {
log.debug("Scanning web.xml for controller servlet mapping");
}
InputStream input =
getServletContext().getResourceAsStream("/WEB-INF/web.xml");
try {
digester.parse(input);
} catch (IOException e) {
log.error(internal.getMessage("configWebXml"), e);
throw new ServletException(e);
} catch (SAXException e) {
log.error(internal.getMessage("configWebXml"), e);
throw new ServletException(e);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
log.error(internal.getMessage("configWebXml"), e);
throw new ServletException(e);
}
}
}
// Record a servlet context attribute (if appropriate)
if (log.isDebugEnabled()) {
log.debug("Mapping for servlet '" + servletName + "' = '" +
servletMapping + "'");
}
if (servletMapping != null) {
getServletContext().setAttribute(Globals.SERVLET_KEY, servletMapping);
}
}
/**
* Perform the standard request processing for this request, and create
* the corresponding response.
*
* @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 is thrown
*/
protected void process(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
RequestUtils.selectModule(request, getServletContext());
getRequestProcessor(getModuleConfig(request)).process
(request, response);
}
// -------------------------------------------------------- Private Methods
/**
* Perform backwards-compatible configuration of the default module's
* controller configuration from servlet initialization parameters (as
* were used in Struts 1.0).
*
* @param config The ModuleConfig object for the default module
*
* @since Struts 1.1
* @deprecated Will be removed in a release after Struts 1.1.
*/
private void defaultControllerConfig(ModuleConfig config) {
String value = null;
ControllerConfig cc = config.getControllerConfig();
value = getServletConfig().getInitParameter("bufferSize");
if (value != null) {
cc.setBufferSize(Integer.parseInt(value));
}
value = getServletConfig().getInitParameter("content");
if (value != null) {
cc.setContentType(value);
}
value = getServletConfig().getInitParameter("locale");
// must check for null here
if (value != null) {
if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)) {
cc.setLocale(true);
} else {
cc.setLocale(false);
}
}
value = getServletConfig().getInitParameter("maxFileSize");
if (value != null) {
cc.setMaxFileSize(value);
}
value = getServletConfig().getInitParameter("nocache");
if (value != null) {
if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)) {
cc.setNocache(true);
} else {
cc.setNocache(false);
}
}
value = getServletConfig().getInitParameter("multipartClass");
if (value != null) {
cc.setMultipartClass(value);
}
value = getServletConfig().getInitParameter("tempDir");
if (value != null) {
cc.setTempDir(value);
}
}
/**
* Perform backwards-compatible configuration of an ActionFormBeans
* collection, and expose it as a servlet context attribute (as was
* used in Struts 1.0). Note that the current controller code does
* not (and should not) reference this attribute for any reason.
*
* @param config The ModuleConfig object for the default app
*
* @since Struts 1.1
* @deprecated Will be removed in a release after Struts 1.1.
*/
private void defaultFormBeansConfig(ModuleConfig config) {
FormBeanConfig fbcs[] = config.findFormBeanConfigs();
ActionFormBeans afb = new ActionFormBeans();
afb.setFast(false);
for (int i = 0; i < fbcs.length; i++) {
afb.addFormBean((ActionFormBean) fbcs[i]);
}
afb.setFast(true);
getServletContext().setAttribute(Globals.FORM_BEANS_KEY, afb);
}
/**
* Perform backwards-compatible configuration of an ActionForwards
* collection, and expose it as a servlet context attribute (as was
* used in Struts 1.0). Note that the current controller code does
* not (and should not) reference this attribute for any reason.
*
* @param config The ModuleConfig object for the default app
*
* @since Struts 1.1
* @deprecated Will be removed in a release after Struts 1.1.
*/
private void defaultForwardsConfig(ModuleConfig config) {
ForwardConfig fcs[] = config.findForwardConfigs();
ActionForwards af = new ActionForwards();
af.setFast(false);
for (int i = 0; i < fcs.length; i++) {
af.addForward((ActionForward) fcs[i]);
}
af.setFast(true);
getServletContext().setAttribute(Globals.FORWARDS_KEY, af);
}
/**
* Perform backwards-compatible configuration of an ActionMappings
* collection, and expose it as a servlet context attribute (as was
* used in Struts 1.0). Note that the current controller code does
* not (and should not) reference this attribute for any reason.
*
* @param config The ModuleConfig object for the default app
*
* @since Struts 1.1
* @deprecated Will be removed in a release after Struts 1.1.
*/
private void defaultMappingsConfig(ModuleConfig config) {
ActionConfig acs[] = config.findActionConfigs();
ActionMappings am = new ActionMappings();
am.setServlet(this);
am.setFast(false);
for (int i = 0; i < acs.length; i++) {
am.addMapping((ActionMapping) acs[i]);
}
am.setFast(true);
getServletContext().setAttribute(Globals.MAPPINGS_KEY, am);
}
/**
* Perform backwards-compatible configuration of the default module's
* message resources configuration from servlet initialization parameters
* (as were used in Struts 1.0).
*
* @param config The ModuleConfig object for the default module
*
* @since Struts 1.1
* @deprecated Will be removed in a release after Struts 1.1.
*/
private void defaultMessageResourcesConfig(ModuleConfig config) {
String value = null;
MessageResourcesConfig mrc =
config.findMessageResourcesConfig(Globals.MESSAGES_KEY);
if (mrc == null) {
mrc = new MessageResourcesConfig();
mrc.setKey(Globals.MESSAGES_KEY);
config.addMessageResourcesConfig(mrc);
}
value = getServletConfig().getInitParameter("application");
if (value != null) {
mrc.setParameter(value);
}
value= getServletConfig().getInitParameter("factory");
if (value != null) {
mrc.setFactory(value);
}
value = getServletConfig().getInitParameter("null");
if (value != null) {
if (value.equalsIgnoreCase("true") ||
value.equalsIgnoreCase("yes")) {
mrc.setNull(true);
} else {
mrc.setNull(false);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -