Hey guys, I'm having a problem with uploading files to a remote server. I just want the visitor to be able to upload a file, and have it go into the uploads directory of my website. My website root is "C:\tomcat\webapps\ROOT", and the uploads directory is at "C:\tomcat\webapps\ROOT\uploads". Both "upload.html" and "upload.jsp" are located in "C:\tomcat\webapps\ROOT". I've been playing around with this for a while and can't get it to work. Can someone please point me in the right direction?
Upload.html:
<html>
<head>
<title>File Upload</title>
<body>
<form action="upload.jsp" method="post" name="uploadform" id="uploadform" enctype="multipart/form-data">
<p><strong>Upload file</strong><br>
<input type="file" name="uploadfile" size="50"></p>
<p> <input type="image" name="Submit" value="Upload" src="images/button2.gif"></p>
</form>
</body>
</html>
Upload.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.*" import="java.io.*"%>
<%
String path=request.getParameter("filename");
String newPath="";
int count=0;
if(path!=null)
{
ArrayList arr=new ArrayList();
StringTokenizer st=new StringTokenizer(path,"\\");
while(st.hasMoreTokens())
{
arr.add(count,st.nextToken());
count++;
}
// create ur own path
newPath="C:\\tomcat\\webapps\\ROOT\\uploads"+arr.get(count-1);
int c;
FileInputStream fis=new FileInputStream(path);
FileOutputStream fos=new FileOutputStream(newPath);
while((c=fis.read())!=-1)
{
fos.write((char)c);
}
}
out.println("Upload Successful!");
out.println("<br>");
out.println("1.File1 Uploaded from :: "+path);
out.println("<br>");
out.println("2.Uploaded File1 is Saved in :: "+newPath);
%>