配置struts2总是失败,错误信息如下:
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了配置struts2总是失败,错误信息如下:相关的知识,希望对你有一定的参考价值。
2012-3-31 16:26:54 org.apache.catalina.startup.HostConfig checkResources
信息: Reloading context [/struts2]
2012-3-31 16:26:54 org.apache.catalina.core.StandardContext stop
信息: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/struts2] has not been started
2012-3-31 16:26:55 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatchar.filterDispatcher
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:249)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3693)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4340)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1105)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1203)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
at java.lang.Thread.run(Thread.java:619)
2012-3-31 16:26:55 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2012-3-31 16:26:55 org.apache.catalina.core.StandardContext start
严重: Context [/struts2] startup failed due to previous errors
这个太明显了吧,你的错误信息仔细看一下:
java.lang.ClassNotFoundException: org.apache.struts2.dispatchar.filterDispatcher
怎么会是dispatchar.fiterDispatcher.应该是你的web.xml配置文件写错了,应该是:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
要注意大小写
追问谢谢,这个确实写错了,我改正后,又出现了别的警告:
警告: Could not create JarEntryRevision for [jar:file:/F:/作业/jsp/.metadata/.me_tcat/webapps/struts2/WEB-INF/lib/struts2-core-2.3.1.2.jar]!
java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
这只是第一个警告,有字数限制,所以只写了一个,你有邮箱或是QQ号吗,我把项目发给你帮我调试下好吗?
嗯,拦截了,照着教程配的,web.xml和struts.xml的配置都应该没问题,按要求加了5个必要的包。
谢谢你~
commons-logging.jar 这个包有吗,加上试试
追问commons-logging.jar这个包加了
加上commons-lang.jar这个包还是不行
谢谢~
struts中读取外部配置文件信息
1、在tomcat中webapps目录下放置一个config.properties配置文件;
2、在监听的时候读取写入src目录下;
3、通过Properties类再次读取,可以在service层获取到,具体代码如下:
1、监听类,实现ServletContextListener接口
public class InitJDBCListener implements ServletContextListener {
private static final Logger log = Logger.getLogger(InitJDBCListener.class);
public void contextInitialized(ServletContextEvent event) {
ServletContext context = event.getServletContext();
// autoSetupJDBC(context);
loadJDBCProperties(context);
// 加载项目配置文件
loadConfigProperties(context);
// 此时, web.xml 中的context-param 元素已经被加载到ServletContext 对象中。
setWPSFlag(context);
setJDBCKeys(context);
}
private void loadConfigProperties(ServletContext sc){
log.info("加载项目配置文件");
File newMsgProperties = getNewMsgPropertiesFile(sc);
File oldMsgProperties = getOldMsgPropertiesFile(sc);
try {
setMsgProperties(oldMsgProperties, newMsgProperties);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void setMsgProperties(File oldMsgProperties,File newMsgProperties) throws IOException{
if(newMsgProperties != null && oldMsgProperties != null){
FileInputStream fis = new FileInputStream(newMsgProperties);
FileOutputStream fos = new FileOutputStream(oldMsgProperties);
byte[] bs = new byte[fis.available()];
fis.read(bs);
fos.write(bs);
fos.flush();
fis.close();
fos.close();
}
}
private File getOldMsgPropertiesFile(ServletContext sc) {
String appDir = sc.getRealPath(File.separatorChar + "");
String msgPropertiesPath = appDir + "WEB-INF" + File.separatorChar
+ "classes" + File.separatorChar + "config.properties";
File msgFile = new File(msgPropertiesPath);
if (msgFile.exists())
return msgFile;
return null;
}
private File getNewMsgPropertiesFile(ServletContext sc) {
String appDir = sc.getRealPath(File.separatorChar + "");
File appDirFile = new File(appDir);
String appContainerPath = appDirFile.getParent();
String msgPropertiesPath = appContainerPath + File.separatorChar + "config_gagb" + File.separatorChar
+ "config.properties";
File msgFile = new File(msgPropertiesPath);
if (msgFile.exists())
return msgFile;
return null;
}
}
2、在web.xml中配置监听,代码如下:
<!-- 必须放在ContextLoaderListener之前-->
<listener>
<listener-class>
org.gagb.webapp.listener.InitJDBCListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
3、通过Properties 读取配置文件:
/**
* 读取配置文件
* config.properties放在src目录下
* @return
*/
public static Properties getConfigProperties() {
Properties prop = new Properties();
try {
java.net.URL url = CommonUtil.class.getResource("/config.properties");
String savePath = url.getPath();
// 以下方法读取属性文件会缓存问题
// InputStream in = PropertiesUtils.class
// .getResourceAsStream("/config.properties");
InputStream in = new BufferedInputStream(new FileInputStream(savePath));
prop.load(in);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return prop;
}
4、在serve中添加Properties静态变量:
private static Properties pro = CommonUtil.getConfigProperties();
5、在方法中根据key获取value:
String adcode = pro.getProperty(Constants.AD_CODE);
6、如果在struts.xml中配置了<constant name="struts.custom.i18n.resources" value="ApplicationResources,errors,jdbc,gis,axis,msg,config" /> 则可以直接通过getText("key")获取;
本文出自 “画江湖之不良人” 博客,谢绝转载!
以上是关于配置struts2总是失败,错误信息如下:的主要内容,如果未能解决你的问题,请参考以下文章
在可视化代码中执行 python 但失败(错误信息:python 路径配置.....)
SSH框架整合遇到的错误——Struts2.5 action跳转出现错误