hi,
there is a ReloadAction in struts1.0, but no in struts1.1.
i try to extend ActionServlet to reload by myself,the code is below:
---------------------
public void reload() throws IOException, ServletException {
// Shut down our existing environment
super.destroy();
super.init();
}
--------------------
when i invoke the reload() method in my Action class by web,there is a
NullPointException.
then i try to override the init() and destroyApplications() method in my
ExtendedActionServlet.java ,like this:
but there is nothing happend,when i modify the struts-config.xml or MessageResource
file,there no any change.....why?thks a lot.......
------------------
package com;
import org.apache.struts.action.*;
import java.io.IOException;
import javax.servlet.ServletException;
import org.apache.struts.util.*;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.MissingResourceException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.beanutils.converters.BooleanConverter;
import org.apache.commons.beanutils.converters.ByteConverter;
import org.apache.commons.beanutils.converters.CharacterConverter;
import org.apache.commons.beanutils.converters.DoubleConverter;
import org.apache.commons.beanutils.converters.FloatConverter;
import org.apache.commons.beanutils.converters.IntegerConverter;
import org.apache.commons.beanutils.converters.LongConverter;
import org.apache.commons.beanutils.converters.ShortConverter;
import org.apache.commons.collections.FastHashMap;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.Rule;
import org.apache.commons.digester.RuleSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.ApplicationConfig;
import org.apache.struts.config.ConfigRuleSet;
import org.apache.struts.config.ControllerConfig;
import org.apache.struts.config.DataSourceConfig;
import org.apache.struts.config.FormBeanConfig;
import org.apache.struts.config.ForwardConfig;
import org.apache.struts.config.MessageResourcesConfig;
import org.apache.struts.config.PlugInConfig;
import org.apache.struts.taglib.html.Constants;
import org.apache.struts.upload.MultipartRequestWrapper;
import org.apache.struts.util.GenericDataSource;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.MessageResourcesFactory;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ServletContextWriter;
import org.xml.sax.InputSource;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class ExtendedActionServlet extends ActionServlet{
public ExtendedActionServlet() {
super();
System.out.println("we have use ExtendedActionServlet!!!!! ");
}
public void init() throws ServletException {
initInternal();
initOther();
initServlet();
// Initialize application modules as needed
getServletContext().setAttribute(Action.ACTION_SERVLET_KEY, this);
ApplicationConfig ac = initApplicationConfig("", config);
initApplicationMessageResources(ac);
initApplicationDataSources(ac);
initApplicationPlugIns(ac);
Enumeration names = getServletConfig().getInitParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (!name.startsWith("config/")) {
continue;
}
String prefix = name.substring(6);
ac = initApplicationConfig
(prefix, getServletConfig().getInitParameter(name));
initApplicationMessageResources(ac);
initApplicationDataSources(ac);
initApplicationPlugIns(ac);
}
//destroyConfigDigester();
}
protected void destroyApplicationsSelf() {
ArrayList values = new ArrayList();
Enumeration names = getServletContext().getAttributeNames();
while (names.hasMoreElements()) {
values.add(names.nextElement());
}
Iterator keys = values.iterator();
while (keys.hasNext()) {
String name = (String) keys.next();
Object value = getServletContext().getAttribute(name);
if (value instanceof ApplicationConfig) {
ApplicationConfig config = (ApplicationConfig) value;
try {
//config.removeMessageResourcesConfig(config.findMessageResourcesConfig(Action.MESSAGE_KEY));
//getRequestProcessor(config).destroy();
config = null;
getServletContext().removeAttribute(Action.APPLICATION_KEY);
getServletContext().removeAttribute(Action.DATA_SOURCE_KEY);
getServletContext().removeAttribute(Action.MAPPING_KEY);
getServletContext().removeAttribute(Action.MESSAGE_KEY);
getServletContext().removeAttribute(Action.MESSAGES_KEY);
getServletContext().removeAttribute(Action.ACTION_SERVLET_KEY);
getServletContext().removeAttribute(Action.DATA_SOURCE_KEY);
getServletContext().removeAttribute(Action.ERROR_KEY);
getServletContext().removeAttribute(Action.EXCEPTION_KEY);
getServletContext().removeAttribute(Action.LOCALE_KEY);
getServletContext().removeAttribute(Action.MULTIPART_KEY);
getServletContext().removeAttribute(Action.PLUG_INS_KEY);
getServletContext().removeAttribute(Action.REQUEST_PROCESSOR_KEY);
getServletContext().removeAttribute(Action.SERVLET_KEY);
getServletContext().removeAttribute(Action.TRANSACTION_TOKEN_KEY);
} catch (Throwable t) {
}
}
}
}
public void reload() throws IOException, ServletException {
this.destroyApplicationsSelf();
destroyInternal();
this.init();
}
}
---------------
Regards,
badi