0

When I upload a file using <input type="file"> in a HTML form and I give the action as <form action=auth> where 'auth' ia a servlet. Now I want to know that When user press Submit button where does the file reside? If in Servlet I want to retrieve the file, What should I do?
Edit
Now I read this file(pdf) using java libraries like

 public void doGet(HttpServletRequest req, HttpServletResponse resp) 
 {
try {
      String INPUTFILE=req.getParameter("filename");
      System.out.println(INPUTFILE);
      PdfReader reader = new PdfReader(INPUTFILE);
      int n = reader.getNumberOfPages();
      System.out.println(n);

      String str=PdfTextExtractor.getTextFromPage(reader, 2); //Extracting the content from a particular page.
      System.out.println(str);


} <br>

But it shows the following error java.io.IOException: java_learn.PDF not found as file or resource

suraj
  • 1,828
  • 12
  • 36
  • 64
  • 2
    The web server is getting a `POST` HTTP request. It can do whatever it wants with the data. – Basile Starynkevitch Apr 25 '12 at 08:28
  • @Basile I want to retrieve that file using servlet? How should i do that? – suraj Apr 25 '12 at 08:34
  • I don't know what you call a servlet! Perhaps it is a framework offering you some way of handling the data in the HTTP request? – Basile Starynkevitch Apr 25 '12 at 08:38
  • public void doGet(HttpServletRequest req, HttpServletResponse resp) { String INPUTFILE=req.getParameter("filename"); System.out.println(INPUTFILE); PdfReader reader = new PdfReader(INPUTFILE);} Now it is not retrieving the pdf file – suraj Apr 25 '12 at 08:44
  • @BasileStarynkevitch I edited my question for clarification – suraj Apr 25 '12 at 08:51
  • where is it giving that error on which line? – Prakash K Apr 25 '12 at 09:08
  • @PrakashK It gives error at this line PdfReader reader = new PdfReader(INPUTFILE); as INPUTFILE just gives the name of file and not the complete path – suraj Apr 25 '12 at 09:19

1 Answers1

1

As stated in the HTML specification you have to use the POST method and the enctype attribute of the form has to be set to "multipart/form-data".

Here is detailed answer by BalusC to upload file.

Here is kick off example to download file

Community
  • 1
  • 1
Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96