File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes what is wrong with my code? trouble extracting input from Textarea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "what is wrong with my code? trouble extracting input from Textarea" Watch "what is wrong with my code? trouble extracting input from Textarea" New topic
Author

what is wrong with my code? trouble extracting input from Textarea

Stephen Wei
Ranch Hand

Joined: Oct 09, 2001
Posts: 73
Hello all, I want my servlet to extract the input from the textarea, then remove all the new line characters, not working well, what is wrong? Can someone help please?
Here is what it looks like:
String temp = request.getParameter(textareaName);
//assume temp is not null.
StringTokenizer st = new StringTokenizer(temp, "\n", false);
StringBuffer buffer = new StringBuffer("");
while(st.hasMoreTokens()){
buffer.append(st.nextToken());
}
String filtered = buffer.toString();
//insert filtered into DB
With the above code, when I extract the string from the DB and read it by excel, it keep returning newline, what is wrong?
Is there something special reading text from Textarea? Can I remove the new line by adding "WRAP = virtual, or WRAP=soft"? But IE and NS use different value for WRAP attribute, I guess I can not satisfy both browsers at the same time...
Please help.
THanks


Sun Certified Programmer for Java Platform
Jayson Chacko
Greenhorn

Joined: Feb 13, 2002
Posts: 1
Try this
new StringTokenizer(temp, "\n\r", false);
I think "\r" is also can come as newline.
Stephen Wei
Ranch Hand

Joined: Oct 09, 2001
Posts: 73
THanks Jayson!
It worked for me, solved my problem.
It was so cool!
JavaRanch is certainly great, I solved many problems here, keep coming!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is wrong with my code? trouble extracting input from Textarea