Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

textarea string

Posted on 2011-04-27
9
Medium Priority
?
394 Views
Last Modified: 2012-05-11
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..
0
Comment
Question by:shragi
9 Comments
 
LVL 23

Expert Comment

by:cmalakar
ID: 35476170
>>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.

0
 
LVL 47

Expert Comment

by:for_yan
ID: 35476204
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

0
 
LVL 47

Expert Comment

by:for_yan
ID: 35476223
Oh yes, about get and post - I misunderstood,
I thought you meant overall limitations.
Surre of course use post for big chunks of data
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:CEHJ
ID: 35476281
>>wat if i post multiple lines of data in text area then the above condition fails..

The linefeeds will be included inside the String
0
 

Author Comment

by:shragi
ID: 35476422
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")
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35476478
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"
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35476603
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

0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 35476892
So if you are looking for "eureka" and if you are not sure if that can
be broken by the end of line you can read from the String you got
from req.getParameter() line by line either using BytaeArrayInputStream
or Scanner and cocatenate all lines into one like that:

String s0 = "";
Scanner in = new Scanner(str);
while(in.hasNextLine()) {
    s0 += in.nextLine();
}

and then look for "eureka"
using the same s0.undexOf("eureka") method

Of course if you are sure it is not split by end of line,
then you don't need to do this concatenation
 

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35505355
>>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

0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question