如何绕过Servlet引擎的权限管理,将信息写入配置文件 存取在application中,只要服务不重起就不会消失,看一看application的生命周期 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to biggie(飞碟) :我要的就是服务器重起之后还可以load进来否则很容易实现,没有必要写文件 还有,我实在没找到application在哪里,我只是写了一个Servlet而已不过,还是谢谢你的回复 在servlet中可以写文件啊,在servlet的init()函数中读出文件,在destroy函数中写入文件。import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class InitDestroyCounter extends HttpServlet { int count; public void init() throws ServletException { // Try to load the initial count from our saved persistent state FileReader fileReader = null; BufferedReader bufferedReader = null; try { fileReader = new FileReader("InitDestroyCounter.initial"); bufferedReader = new BufferedReader(fileReader); String initial = bufferedReader.readLine(); count = Integer.parseInt(initial); return; } catch (FileNotFoundException ignored) { } // no saved state catch (IOException ignored) { } // problem during read catch (NumberFormatException ignored) { } // corrupt saved state finally { // Make sure to close the file try { if (bufferedReader != null) { bufferedReader.close(); } } catch (IOException ignored) { } } // No luck with the saved state, check for an init parameter String initial = getInitParameter("initial"); try { count = Integer.parseInt(initial); return; } catch (NumberFormatException ignored) { } // null or non-integer value // Default to an initial count of "0" count = 0; } public void destroy() { super.destroy(); // entirely optional saveState(); } public void saveState() { // Try to save the accumulated count FileWriter fileWriter = null; PrintWriter printWriter = null; try { fileWriter = new FileWriter("InitDestroyCounter.initial"); printWriter = new PrintWriter(fileWriter); printWriter.println(count); return; } catch (IOException e) { // problem during write // Log the exception. See Chapter 5. } finally { // Make sure to close the file if (printWriter != null) { printWriter.close(); } } }} 速救啊,sql死慢啊,模糊查询的问题 高手来帮忙啊,小弟谢谢了 JSTL 循环想获得循环第几次 showModalDialog 打开模态 子窗口 后,怎样 隐藏 父窗口? struts项目出错 jsp链接什么时候用jsp,什么时候用do 高分请各位过来人指教! 用jdbcd调用数据库的问题:装了一个sql 2000 driver for jdbc,在jbuilt中可以成功调用数据,但在jsp中调用时出错。 [求助]循环与表单---问题阐明得很清楚,请帮助!(在线) 输出流怎么写啊 怎样在同一页面内设置不同权限 高手请支招啊。100分恭候!
我要的就是服务器重起之后还可以load进来
否则很容易实现,没有必要写文件
不过,还是谢谢你的回复
import javax.servlet.*;
import javax.servlet.http.*;public class InitDestroyCounter extends HttpServlet { int count; public void init() throws ServletException {
// Try to load the initial count from our saved persistent state
FileReader fileReader = null;
BufferedReader bufferedReader = null;
try {
fileReader = new FileReader("InitDestroyCounter.initial");
bufferedReader = new BufferedReader(fileReader);
String initial = bufferedReader.readLine();
count = Integer.parseInt(initial);
return;
}
catch (FileNotFoundException ignored) { } // no saved state
catch (IOException ignored) { } // problem during read
catch (NumberFormatException ignored) { } // corrupt saved state
finally {
// Make sure to close the file
try {
if (bufferedReader != null) {
bufferedReader.close();
}
}
catch (IOException ignored) { }
} // No luck with the saved state, check for an init parameter
String initial = getInitParameter("initial");
try {
count = Integer.parseInt(initial);
return;
}
catch (NumberFormatException ignored) { } // null or non-integer value // Default to an initial count of "0"
count = 0;
}
public void destroy() {
super.destroy(); // entirely optional
saveState();
} public void saveState() {
// Try to save the accumulated count
FileWriter fileWriter = null;
PrintWriter printWriter = null;
try {
fileWriter = new FileWriter("InitDestroyCounter.initial");
printWriter = new PrintWriter(fileWriter);
printWriter.println(count);
return;
}
catch (IOException e) { // problem during write
// Log the exception. See Chapter 5.
}
finally {
// Make sure to close the file
if (printWriter != null) {
printWriter.close();
}
}
}
}