Win a copy of Fixing your Scrum this week in the Agile forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

readLine() method return -1

 
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everybody,

I am submitting a form in jsp file to a servlet :-

Partial jsp file contents are :-

<form name="searchexcel" method="POST" ENCTYPE="multipart/form-data">
<input type=file name="filename" >
</form>

partial code in servlet as follows :-

ServletInputStream sis = request.getInputStream();
byte[] b = new byte[1024];
int x=0;
while((x=sis.readLine(b,0,1024))>-1) {

*****
}


readline method is returning -1 at first attempt itself. It will be a great help if Can any one inform what could be the possible reasons for it.

Regards,
Neeraj.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With servlet response you have a choice - you can either read the body of the request with request.getInputStream() -OR- you can use the response getParameter method to get form parameters. This is because the servlet engine has to read the request body input stream in order to find and parse the form parameters for you. The return of -1 indicates that the InputStream is already at the end of data.
The JavaDocs for ServletRequest.getParameter() discusses this.
Bill
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as your form type is multipart/form-data. you will get null, if use request.getParameter(String str).
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might be interested in the MultipartRequest and associated classes available in the O'Reilly Servlets package.

Jules
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic