为什么文件上传不了啊???

来源:互联网 发布:cpa软件服务 编辑:程序博客网 时间:2024/04/27 14:51

我自己本机 上传文件是ok的

别人访问http://172.25.49.35:8080/servlet/login可以正常获得网页
上传文件后也没有报错,就是上传不了

代码如下

login.html是放在apache servlet目录下的

<html>
 <head>
  <title align="center">Welcome to the Share PPT Home ! </title>
 </head>
<body> 
 <h3 align="center">welcome to the share PPT Center</h3>  
  <form action = "http://172.25.49.35:8080/servlet/login"
  method="get">
<div align="center">
  上传者 ID 
  <input type="text" name="OwnerID" size ="9"/>
  <br>
   
  作者Author
  <input type="text" name="Author" size ="9"/>
  <br>
   
  Permission
<input type ="radio" name="Permission" value="0" checked/>共享 
<input type="radio" name="Permission" value="1"/>仅好友可见 
  <input type="radio" name="Permission" value="2"/>仅自己可见 
  <br>
   
  选择要上载的文件 
  <input type="file" name="filename" >
  <br>
  <input type="submit" value="上载" >
  </div>
   
</form>
</body>
</html>

login.java


import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
import javax.servlet.*;
import javax.servlet.http.*;
import DB.InsertFile;
import DB.InsertUser;

//upload a ppt or something else
public class login extends HttpServlet{

/**
* @param args
*/
public void doGet(HttpServletRequest request , HttpServletResponse response)
throws ServletException,IOException
{
String OwnerIDstr = request.getParameter("OwnerID").trim();//Owner name
String Author = request.getParameter("Author").trim();
String Permissionstr = request.getParameter("Permission");
String filename = request.getParameter("filename");
response.setContentType("text/html");
//PrintWriter out = response.getWriter();
if(OwnerIDstr.length()==0 || Author.length()==0 || filename.length()==0)
{
//out.println("please complete the infomation ! ");
return;
}
int Permission = Integer.parseInt(Permissionstr);
int OwnerID = Integer.parseInt(OwnerIDstr);
File file = new File(filename);
int index;
for(index=filename.length()-1;index>=0;index--)
{
if(filename.charAt(index)=='//')
break;
}

String newName = filename.substring(index+1);
String a = new String(newName);
/*testout.write("a" + newName);*/
try 
{  
InsertFile file1 = new InsertFile(OwnerID,newName,Author,Permission);
boolean flag = file1.insert();
DataInputStream input=new DataInputStream(
new FileInputStream(filename));  
int r;
String dirurl = "D://Program Files//Apache Software Foundation//Tomcat 7.0 //webapps//servlet//PPT//" + OwnerID;
/*testout.write(dirurl);*/
File dir = new File(dirurl);
//out.write("mkdir:" + dir.mkdir());
DataOutputStream tofile=new DataOutputStream(
new FileOutputStream(dirurl+"//"+newName));

while((r=input.read())!=-1)
{
//out.write((byte)r);
tofile.write((byte)(r));
}
input.close();
//out.close();
tofile.close();

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}

 为什么别人的文件上载不了呢,是我这边访问不到他们的文件吗?
 求高人指点啊~~~
 本人刚刚开始自学网页制作,是想做一个ppt在线共享网站,可是现在连文件都上传不了,急啊~~~~

 另外谁可以讲讲jsp是什么啊?java+apache就是jsp了吗?

 求教~~~