Link to home
Start Free TrialLog in
Avatar of shragi
shragiFlag for India

asked on

textarea string

I had a textarea field and I stored the value from textarea into string...
i pasted huge data into textarea...
using servlets i stored
String storetxtarea = req.getParameter("textareavariable")

now i had two problems...

1)I heard that get method gets maximum 1k how about huge data should i use Post method
2. suppose i had data less than 1k and stored in string how do i get to the end of the string.
should i use while(storetxtarea.equals("\n");
wat if i post multiple lines of data in text area then the above condition fails..

so anyideas for above 2 problems..
Avatar of cmalakar
cmalakar
Flag of India image

>>I heard that get method gets maximum 1k how about huge data should i use Post method

Yes get request has a limit, and use post for more data.

>>suppose i had data less than 1k and stored in string how do i get to the end of the string.

What do you mean by getting to the end of string ?

Your string will have all the lines that you pasted in your text area.

when you use String s = req.getParameter("textareavaraible")
your String s gets all its lines witin it, including end of lines
between them

You can then
set up InputStream in = new InputStream(new ByteArrrayInputStream(s.gettBytes())
and read this text as if you are reading lines
from file - so if you need only first line you can read only first line


About totla of 1K in textara - don't kniow - haven't heard about it
seems to be a hard constraint

Oh yes, about get and post - I misunderstood,
I thought you meant overall limitations.
Surre of course use post for big chunks of data
Avatar of CEHJ
>>wat if i post multiple lines of data in text area then the above condition fails..

The linefeeds will be included inside the String
Avatar of shragi

ASKER

data in textarea:

"hi hello
bye

how are you

eureka

i am fine"



so, when I use
String str = req.getParameter("textareavaraible")
I had my entire string in str
and i want to search for somestring "eureka" in the str

if I search while(str.equals("\n"))
then I will not find eureka becoz  the while loop stops at "bye"

how can I search till end...

and is the below syntax correct

String storetxtarea = req.postParameter("textareavariable")
you can just search

storetextarea.indexOf("eureka") then at least
your "eureka" is broken by the end of line
you'll find it.
If you want to find it even if it  is broken by the end of line then you probably
want to do it with regular expressions
If you know that it is not broken then indexOf will return you the indedex of the charcter across the whole string where it begins
or -1 if there is no "ereka"
You can do the following to read line-wise
Scanner in = new Scanner(str);
while(in.hasNextLine()) {
   String s = in.nextLine();
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>and cocatenate all lines into one like that:

There's absolutely no need to do that. Simply the following would suffice:
int ixFound = str.replaceAll("\r\n", "").indexOf("eureka");

Open in new window