This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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>");
}
}
 
wood burning stoves
 
subject: servlets-urgent pl reply