• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to read a input type file in servlet and display the contents of a file in servlet

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jsp page wherein i have to passs the file as input and read the contentsn of a file in servlet.

upload.jsp

<FORM METHOD=POST ENCTYPE="multipart/form-data" ACTION="upload"> File to upload: <INPUT TYPE=FILE NAME="upfile">
<INPUT TYPE=SUBMIT VALUE="Submit">

upload.java

//In upload servlet page i have tried to read the contents of a file in doPost method. I have used

String t1=request.getParameter("upfile");

//It shows null. How to read the content in a file and display in servlet?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.
We have forum dedicated for servlet questions. I will move your post over there for you.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see the JspFaq for information on file uploading.

Also, using all uppercase for HTML sort of went out of fashion in 1998. I'd catch up with the conventions of the times and use all lowercase.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Viswanathan Pachaiyappan wrote:I have a jsp page wherein i have to passs the file as input and read the contentsn of a file in servlet.

upload.jsp

<FORM METHOD=POST ENCTYPE="multipart/form-data" ACTION="upload"> File to upload: <INPUT TYPE=FILE NAME="upfile">
<INPUT TYPE=SUBMIT VALUE="Submit">

upload.java

//In upload servlet page i have tried to read the contents of a file in doPost method. I have used

String t1=request.getParameter("upfile");

//It shows null. How to read the content in a file and display in servlet?



Hi,

It is more complicated than that. The multipart request has a more convoluted structure and you should not start from scratch with its processing.

Please get the library FileUpload from Apache Jakarta, study how to operate with it and that will provide you a solution for your problem.

There are also web frameworks that provide transparent file processing (like Struts etc), but of course your question was about servlets.

Best Regards,
D
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic