File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Posting a form with jQuery to servlet : Losing newlines?

 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

There is a little problem that i do not fully understand...

In the beginning, i used to work on the standard post method with html...using no script...everything went well...Jsp-post -> servlet -> done

Now, when i try to post that same form to a servlet, using jQuery post method, everything goes fin...except that i lose my newlines.

i work with the jQuery serialize() function.

$('form#dataform').serialize()

All textarea's that contain newlines, are converted to the following :

textarea1=line1%0Aline2&textarea2=line1%0Aline2

why not %0D%0A?...i don't know, but i accept it...

BUT, when the data is posted, in the servlet i receive (using req.getParameter(textarea1)...)

textarea1 = line1line2
textarea2 = line1line2

why is the %0A not comming in?

So, in the end, all newlines are gone...

I googled but didn't find an answer that was clear enough...and solutions are not that good...
they are talking about replacing the "%0A" etc etc...

anybody?

thanks in advance!!
 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nobody else ever got this problem? or maybe my question is not clear enough?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How have you determined that the line feeds are gone?
 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

first at the client, i used a script "alert" , where i saw that the linefeeds (0D0A) were converted to only %0A...i even think that this could be browser dependend...
using the jquery .serialize() function.


but, when i read them out in the servlet (like i said, using req.getParameter...), even the %0A is gone!

How im sure? i display them in hex format...no doubt that they are gone! only the hexadecimal representation of the text is shown.
I can assume that this is a common problem, because google is full of it...but no good solution.
But, just because it is a common problem...there must be a standard work around for it...a solution...something...

or am i doing something terrible wrong, i don't know!
i am not "script" specialist, because i want to use it as less as possible, cause of browser dependencies...

for the moment, i "solved" the problem in script by replacing all "%0A" by "--BRAKE--" and in the backend, replacing "--BRAKE--" by "\r\n"
it works, but i don't want to use a crappy solution like this!

If you want, tommorow i can post the code i use, client, server, etc...





 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post an SSCCE showing the issue rather than a lot of code that might not be relevant to the problem.
 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shame on me, shame on me...

I made a simple project like you suggested, just using the basics, and it worked!!

Original problem is, that i use a customized framework, and it takes care of everything. Deep inside the code i found out that all the 10's were replaced by ''.

So everything is ok now...
Actually, the problem raised because jQuery transforms the 0D0A to only 0A...
And a normal html post sends 0D0A...

thanks for the reply!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic