我用myeclipse把我的工程部署到tomcat上并运行之后报下面的错误 哪位大哥帮忙看下怎么回事啊
信息: The listener "com.briup.run.web.listener.SessionListener" is already configured for this context. The duplicate definition has been ignored.
contextInitialized...
java.io.IOException: 系统找不到指定的路径。
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at com.briup.run.web.listener.ContextListener.contextInitialized(ContextListener.java:37)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4350)
....
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2010-3-25 10:34:19 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
修改下代码
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
ServletContext context=arg0.getServletContext();
String path=context.getRealPath("/data/count.dat"); //获得应用程序
的根目录
//先创建目录
String dir=context.getRealPath("/data");
new File(dir).mkdir();
System.out.println("contextInitialized...");
File f=new File(path);
try{
if(!f.exists())
f.createNewFile();
FileInputStream file=new FileInputStream(f);
int count=file.read();
if(count==-1)
count=0;
file.close();
context.setAttribute("count", count);
}catch(Exception e){
e.printStackTrace();
}
}
根据错误提示:SessionListener被配置了两次,看看配置文件关于它的配置。
有两个问题
1.com.briup.run.web.listener.ContextListener在web.xml文件中配置了两次
2.com.briup.run.web.listener.ContextListener.contextInitialized(ContextListener.java:37)
这个监听器创建文件出错
就是这两个监听器的问题
com.briup.run.web.listener.ContextListener
com.briup.run.web.listener.SessionListener
你代码是怎么写的
出错的代码粘出来分析嘛
java.io.IOException: 系统找不到指定的路径。at java.io.WinNTFileSystem.createFileExclusively(Native Method)
解决办法是先创建目录。然后创建文件。
[code="java"]File f=new File("E:/www");
if(!f.exists()){
f.mkdirs();
}
File f1=new File("E:/www/1.txt");
f1.createNewFile();
System.out.println(f1.exists());
[/code]这样才能创建成功