aspose file tools*
The moose likes Servlets and the fly likes servlets-urgent pl reply Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets-urgent pl reply" Watch "servlets-urgent pl reply" New topic
Author

servlets-urgent pl reply

sai sridhar
Greenhorn

Joined: Aug 23, 2001
Posts: 7
Hi all
I upload a file to a webserver using a servlet.
How do i get the name of the file which is uploaded ???I'm using com.orielly.servlet package..
Is there any way to find out the name of the file which is uploaded prior to this line below in the code given down??
MultipartRequest multi =
new MultipartRequest req,"/temp",1024*1024);
If so,pl respond
Your help will be greatly appreciated
Thanks in advance
sridhar
Pl see : down given is my code for uploading a file
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.*;
import java.util.*;
public class Upload extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{

res.setContentType("text/html");
PrintWriter out = res.getWriter();
try{
System.out.println(req.getHeader());
MultipartRequest multi =
new MultipartRequest req,"/temp",1024*1024);
out.println("<html>");
out.println("<head><title>UploadTest</head></title>");
out.println("<body>");
out.println("<h1>upLoadTest</h1>");
out.println("<pre>");
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements())
{
String name = (String)params.nextElement();
String value = multi.getParameter(name);
out.println( name + " = " + value);
}
out.println("</pre>");
out.println("<h3> files : </h3>");
out.println("<pre>");
Enumeration files = multi.getFileNames();
while (files.hasMoreElements())
{
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type = multi.getContentType(name);
File f = multi.getFile(name);
out.println("name : " + name);
out.println("file name : "+ filename);
out.println("type : "+type);
if (f!=null){
out.println("length : " +f.length());
out.println();
}
out.println("</pre>");
}
}
catch(Exception e)
{
out.println("<pre>");
System.out.println(e);
e.printStackTrace(out);
out.println("</pre>");
}
out.println("</body> </html>");
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlets-urgent pl reply
 
Similar Threads
problem with file uploading
problem in using MultipartRequest
HTTP Status 405
Multipart Upload - where does my file go?
How to upload a file using servlets to a webserver