JSP对文件的操作
一、在JSP页面中读取本地文件内容:
<%
try {
BufferedReader in = new BufferedReader(new FileReader("D:/test.txt"));
String file = "";
String temp = "";
while((temp=in.readLine())!=null) {
file += temp + "<br>";
}
out.println(file);
in.close();
out.flush();
} catch(Exception e) {
e.printStackTrace();
}
%>
二、在JSP页面中写入文件内容:
<%
try {
PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("D:/test.txt", true)));
writer.write(content);
writer.close();
out.println("已经写入到文件中");
} catch(Exception e) {
e.printStackTrace();
}
%>
相关文档:
1. jsp:forward标签只能实现本网站内的跳转,即浏览器上显示的依然是之前客户端的页面文件名,而不是跳转后的页面文件名
而response.sendRedirect()可以跳转到任何一个地址的页面,且浏览器上显示的是跳转后的页面文件名
2. 当在之前的客户端页面文件中使用response.setAttribute()存储了某个值后,使 ......
有的时候会忘记,记录一下:
<iframe id="xx" name="xx" width="515" height="177" scrolling="no" border="0" marginwidth="0" marginheight="0" frameborder="0" src="Xx.jsp"></iframe>
要使jsp不变形,主要是marginwidth="0" marginheight="0"两个属性。 ......
session对象是javax.servlet.http.HttpSession类的一个子类对象;在session中保存的对象值在当前用户连接的所有页面中都是可以被访问到的,即session对象是存储在每个打开的IE浏览器中的,不同的用户所对应的session对象一般是不同的;常用方法如下:
setAttribute(String name,Obje ......
一个站点服务器中所有的用户公用一个application对象,当站点服务器开启时,该对象就被创建,直到网站关闭;也就是说:该对象一旦被创建了,它将被保存在服务器上;它的生命周期与服务器的生命周期相同;常用方法如下
setAttribute(String name,Object o):将名字为name,值为o的数据存储到appli ......
Properties properties = new Properties();
File file = new File(request.getRealPath("/") +"\\WEB-INF\\classes\\configs.properties");
FileInputStream fiStream = new FileInputStream(file);
InputStreamRe ......