每次上传的时候总是报 拒绝访问,我google了下,看到说是路径不对,字符串写错,或者权限不够,但是我看了下我的,没写错,路径正确
权限是超级管理员登陆的 怎么回事 ?还望大家给看下
[code="java"]
public String fileupload() {
try {
File file1 = this.getFile();
System.out.println(file1.getName());
String path = ServletActionContext.getServletContext().getRealPath("/upload");
System.out.println(path);
Util.write(path, file);
ServletActionContext.getResponse().getWriter().println("成功");
} catch (Exception e) {
e.printStackTrace();
return INPUT;
}
return "file";
}
[/code]
[code="java"]
//写一个静态的方法,以便调用
public static void write(String path,File file){
final int BUFFER_SIZE = 16 * 1024 ;
try {
InputStream in = null ;
OutputStream out = null ;
try {
in = new BufferedInputStream( new FileInputStream(path), BUFFER_SIZE);
out = new BufferedOutputStream( new FileOutputStream(file), BUFFER_SIZE);
byte [] buffer = new byte [BUFFER_SIZE];
while (in.read(buffer) > 0 ) {
out.write(buffer);
}
} finally {
if ( null != in) {
in.close();
}
if ( null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
[/code]
异常的代码,就一个异常
[code="java"]
upload__683d9dab_11d7b418a9f__8000_00000000.tmp
E:\apache-tomcat-6.0.16\apache-tomcat-6.0.16\webapps\pkm\upload
java.io.FileNotFoundException: E:\apache-tomcat-6.0.16\apache-tomcat-6.0.16\webapps\pkm\upload (拒绝访问。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:137)
at java.io.FileInputStream.(FileInputStream.java:96)
at com.pkm.util.Util.write(Util.java:22)
[/code]
[b]问题补充:[/b]
那个--上一站火星。我当时改了之后但是立马在看文件夹还是只读的
回 jones 为什么我在JSP和struts1.x 里面也是这样写的OK 而struts2 就不行?
[b]问题补充:[/b]
回JSONS 我想我是明白了,但是我怎么把路径给转回来,别让我用字符串一个一个来替换,有什么好的方法没??谢谢
[b]问题补充:[/b]
回JSON
艾,咱也没找到好方法,刚才吃饭之前就是用replaceAll() 不过不知道有没什么方法,直接用上去,不替换的有米有 呵呵
[b]问题补充:[/b]
不行了,同志们,咱转换也不行
upload__14cccc4e_11d7bcd629c__8000_00000000.tmp
E:/apache-tomcat-6.0.16/apache-tomcat-6.0.16/webapps/pkm/upload
java.io.FileNotFoundException: E:\apache-tomcat-6.0.16\apache-tomcat-6.0.16\webapps\pkm\upload (拒绝访问。)
这个不行
File file1 = this.getFile();
System.out.println(file1.getName());
String path = ServletActionContext.getServletContext().getRealPath("//upload");
String root = path.toString().replaceAll("\\\\", "/");
System.out.println(root);
Util.write(root, file);
ServletActionContext.getResponse().getWriter().println("成功");
[b]问题补充:[/b]
JSON 这个东西不行啊,咱还是不能搞定 ,能帮看下吗?
[b]问题补充:[/b]
晕,刚没注意看,我改了下,谁知道没改完 抱歉抱歉