关于删除已上传文件的问题。 String filePath="c:/支出证明单.xls";filePath=filePath.toString();java.io.File myDelFile=new java.io.File(filePath);myDelFile.delete(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你用上面的程序已经可以了filePath就是你的文件的绝对路径 To: leshui(大象无形)我用了你上面的程序可以正确删除硬盘上指定目录的文件,但是我这里始终有问题(路径是由数据库返回的值组成),我用rs.getString直接取值不行,用session传递值也不行...帮我看看好吗?十分感谢!!<%@ page contentType="text/html; charset=gb2312" %><%@ page import = "java.sql.*" %><%!Connection con;Statement stmt;ResultSet rs;%><%try {Class.forName("org.gjt.mm.mysql.Driver");con = DriverManager.getConnection ("jdbc:mysql://localhost/resource_db?user=root&password=");stmt = con.createStatement();String i=request.getParameter("checkbox");rs = stmt.executeQuery("select * from menu_kejian where ID='"+i+"'");while (rs.next()) {String g=rs.getString("Grade_ID");session.setAttribute("Grade",g);String c=rs.getString("Course_ID");session.setAttribute("Course",c);String t=rs.getString("Type_ID");session.setAttribute("Type",t);String f=rs.getString("File");session.setAttribute("File",f);}stmt.executeUpdate ("delete from menu_kejian where ID='"+i+"'");%>删除记录成功!<a href=display.jsp>查看</a><%}catch (ClassNotFoundException e) {out.println("Couldn't load database driver: " + e.getMessage());}catch (SQLException e) {out.println("SQLException caught: " + e.getMessage());}finally {try {if (con != null) con.close();}catch (SQLException ignored) {}}rs.close();stmt.close();con.close();String g1=(String)session.getAttribute("Grade");String c1=(String)session.getAttribute("Course");String t1=(String)session.getAttribute("Type");String f1=(String)session.getAttribute("File");String Path=g1+"/"+c1+"/"+t1+"/"+f1+";String filePath="http://localhost:8080/examples/upload/+path";filePath=filePath.toString();java.io.File myDelFile=new java.io.File(filePath);myDelFile.delete();session.removeAttribute("Grade");session.removeAttribute("Course");session.removeAttribute("Type");session.removeAttribute("File");%>删除文件成功! filePath应该为本地绝对路径吧?如果包含中文名,可能需要编码转换啊^_^ filePath为本地绝对路径的话我就明白了:pString Path=g1+"/"+c1+"/"+t1+"/"+f1+";String filePath="http://localhost:8080/examples/upload/+path";改成String filePath="C:/Program Files/Apache Group/Tomcat 4.1/webapps/examples/upload/"+g1+"/"+c1+"/"+t1+"/"+f1+"";我刚测试,已经通过了,但还是要用session来传递变量,直接返回数据库的值就是不行..不解.... 如何构造一个好的动态网站 ssh对从数据库中读出数据的处理问题 jsp问题怎样知道String investType = (String)session.getAttribute("investtype");从哪来 为什么不能把Collection传到browse.jsp? JSP QQ群:2139326 我的第一个JSP文件还没有搞定,求高人指点。 请大家测试? 求助:jsp的中文问题 jsp在输出时怎样屏蔽html代码 ssh整合, 必须要配事务管理吗? 如何判断一个CachedRowSet对象里是否有纪录 HashTable的使用
filePath就是你的文件的绝对路径
我用了你上面的程序可以正确删除硬盘上指定目录的文件,但是我这里始终有问题(路径是由数据库返回的值组成),我用rs.getString直接取值不行,用session传递值也不行...帮我看看好吗?十分感谢!!<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import = "java.sql.*" %>
<%!
Connection con;
Statement stmt;
ResultSet rs;
%>
<%
try {
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection ("jdbc:mysql://localhost/resource_db?user=root&password=");
stmt = con.createStatement();
String i=request.getParameter("checkbox");
rs = stmt.executeQuery("select * from menu_kejian where ID='"+i+"'");while (rs.next()) {
String g=rs.getString("Grade_ID");
session.setAttribute("Grade",g);String c=rs.getString("Course_ID");
session.setAttribute("Course",c);String t=rs.getString("Type_ID");
session.setAttribute("Type",t);String f=rs.getString("File");
session.setAttribute("File",f);
}stmt.executeUpdate
("delete from menu_kejian where ID='"+i+"'");
%>删除记录成功!
<a href=display.jsp>查看</a>
<%
}catch (ClassNotFoundException e) {
out.println("Couldn't load database driver: " + e.getMessage());
}
catch (SQLException e) {
out.println("SQLException caught: " + e.getMessage());
}
finally {
try {
if (con != null) con.close();
}
catch (SQLException ignored) {}
}rs.close();
stmt.close();
con.close();String g1=(String)session.getAttribute("Grade");
String c1=(String)session.getAttribute("Course");
String t1=(String)session.getAttribute("Type");
String f1=(String)session.getAttribute("File");String Path=g1+"/"+c1+"/"+t1+"/"+f1+";
String filePath="http://localhost:8080/examples/upload/+path";filePath=filePath.toString();
java.io.File myDelFile=new java.io.File(filePath);
myDelFile.delete();session.removeAttribute("Grade");
session.removeAttribute("Course");
session.removeAttribute("Type");
session.removeAttribute("File");
%>
删除文件成功!
String Path=g1+"/"+c1+"/"+t1+"/"+f1+";
String filePath="http://localhost:8080/examples/upload/+path";
改成
String filePath="C:/Program Files/Apache Group/Tomcat 4.1/webapps/examples/upload/"+g1+"/"+c1+"/"+t1+"/"+f1+"";
我刚测试,已经通过了,但还是要用session来传递变量,直接返回数据库的值就是不行..不解....