Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem regarding reading a String  RSS feed

 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

I'm doing a program of uploading a file from a swing application rather than a browser through a servlet . For that i've made a test program which is running successfully but a small problem is coming in the output,When I'm printing the string obtained through BufferedReader the concatenation operators are also getting printed int the output .i want to remove that how can i do that?

The code is provided below:
CLIENTSIDE CODE







SERVLET CODE







Thanking you,
Jignesh
 
Arto Pastinen
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Are you sure you know what are you doing?

Your String s must be correct http request (it must contains http's head/body parts.) that it could work, because your servlet extends from HttpServlet.

If you are just making file upload over HTTP, i suggest that you get familiar with apache's fileupload. (there is others, but this is very common.)

fileupload

.. and you must use correct character encoding in urlencoder/decoder. iso-8859-1 is http default.

Artsi

[ March 04, 2005: Message edited by: Arto Pastinen ]
[ March 04, 2005: Message edited by: Arto Pastinen ]
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Arto,

Thanks for the reply.
But I'm not exactly getting you.You please tell me how to remove the "+" operators coming in the output after reading it in the servlet.
One more thing is that in the CLient code I'm using A InputStream like

InputStream in = urlConnection.getInputStream() ;
This stmt is after dstream.close() in the client code.

Thanking you,
Jignesh
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the sample input and the output you get on the servlet end? You're not doing any string concatenation, though that should result in plus signs in the result of course.

One problem I see is that you use readLine() and then append() the result, but readLine() removes the trailing line separator that it consumes. You can fix that by appending '\n' -- or System.getProperty("line.separator") -- after the read line.
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is that you are using URLEncoder to encode the string you send (which will convert spaces to '+'), but you are just reading, then outputing the raw input at the servlet end. You don't use URLDecoder.

If you are just playing, the go ahead. But if this is for production code, I'd follow previous posters' advice and use something solid, tried & tested like the Jakarta common fileupload.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Horatio Westock:
I think the problem is that you are using URLEncoder to encode the string you send (which will convert spaces to '+'), but you are just reading, then outputing the raw input at the servlet end. You don't use URLDecoder.
Good catch! That will definitely cause the problems. Since the String is in the POST data, there should be no need for URL encoding.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!