Solved

large String problem

Posted on 2004-08-19
15
160 Views
Last Modified: 2010-04-01
Hi,

I have a page A which loads users from a db and passes it into another page B as a String separated by ";".

In page B, I use a String Tokenizer to tokenize the string and for every string obtained, I display it along with a chkbox next to it..

The problem is when page B loads with the received String, it hangs. I found out that the problem is with the String length. If I send a shorter String, the page loads fine but the String I am passing has about 10000 characters (540 words separated by ;).

But what I found strange was that, I loaded this entire String into another variable in a test jsp and it worked fine..

How can I resolve this ??

TIA
0
Comment
Question by:sgaucho
15 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 11839291
Are you passing it in the request URL?

That's probably a bad idea, as some browsers only support a certain length for Strings...

What you can do, is stick it in the session between pages...

in jsp1:

<%
    session.setAttribute( "data", aReallyReallyLongString ) ;
%>

then, in jsp2:

<%
    String reallyLongString = (String)session.getAttribute( "data" ) ;
    session.removeAttribute( "data" ) ;
    if( reallyLongString == null )
    {
        out.println( "<h1>data was null!</h1>" ) ;
    }
%>
0
 

Author Comment

by:sgaucho
ID: 11839414
Its slightly more complicated than that.. didnt post the entire story before :)

Here´s the setup:

I have a JSP page C which has 2 iframes in it whose sources are JSP page A and JSP page B.

Page A loads the users from a db and hv chkboxes beside each user. Once the chkboxes are checked and a button on page C is cliked, a Javascript function collects all the users (generates a string separted by ;)whose chkboxes hv been checked, Loads a hidden field in page B with this value AND then, submits page B.

Thus, page B receives the values as a String in the request url and does what I hv explained above.

Hope this made some sense!
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11839657
> Once the chkboxes are checked and a button on page C is cliked, a Javascript function collects all the users (generates a string separted by ;)whose chkboxes hv been checked, Loads a hidden field in page B with this value AND then, submits page B.

Why can't you just post the checkboxes to pageB as you would normally if they were in a form?

OR you are going to have to have C submit to D, which stores the string in the session, then reloads B

if you see what I mean ;-)

I'm dizzy now ;-)

Tim
0
 
LVL 4

Expert Comment

by:Mr_It
ID: 11839698
Are you saying that after you receive the request (in B), you can put/display the entire string in/from a jsp variable but you cannot process it with the StringTokenizer?

0
 

Author Comment

by:sgaucho
ID: 11839905
Hi Tim,

Your soln for posting the chkboxes directly frm page A to B wud probably work fine but that would need to me to start all over again.. Isnt there a simpler workaround ?

btw, how can I post a form from one iframe to another iframe ? putting a target in the form tag doesnt seem to work..

@ Mr_It,  nope the problem was what Tim pointed out, the request url is not receiving the entire string..
0
 

Author Comment

by:sgaucho
ID: 11839921
Nevermind bout the target..  its ok now..

anycase, wud be much happier if I can resolve this problem without recreating the soln..

thnx
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 35

Expert Comment

by:TimYates
ID: 11839956
I don't think you can...  You can't put that many chars into an HTTP-GET (url string), and you can't get at the session from inside javascript...  So you will have to post the form, and put it in the session, and reload the other page (as far as I know) :-(
0
 

Author Comment

by:sgaucho
ID: 11840084
hmm.. wudnt it be possible to write to different hidden fields ?? i.e. when Page C is reading values and writing them to a hidden field in B, instead of writing all the values into the same hidden field, why not write to 3 or 4 hidden fields in B before submitting B ? Not that I like doing this but trying a last ditch op before starting again! ??

Meanwhile, apparently my prob with submitting iframe is not solved as I had thought ? So, How can I submit a form in one iframe to another iframe ?? just target doesnt seem sufficient..

thnx
0
 
LVL 35

Accepted Solution

by:
TimYates earned 125 total points
ID: 11840159
Do you mean "IFRAME" or "FRAME"?

IFrame I have no idea...not even sure you can submit from one to the other...

> to write to different hidden fields

Can you post your code?  Are you passing it in hidden fields?  I thought you were building a query string up with javascript?  Are you setting hidden fields?

Splititing it into two hidden fields will just give you real problems in the future :-(

Adding another JSP is the only really neat solution...
0
 
LVL 3

Expert Comment

by:ss_p
ID: 11842089
Are you using

do_get() method.

If you are using do_get().

Then try to change to d0_Post().

bcoz there is lenght of characters in posting with do_get method.

I think this might be the problem

please get back

Prasannaa
0
 

Expert Comment

by:iglez
ID: 11896998
ypu can try
StringBuffer

StringBuffer sBuffer = new StringBuffer();

sBuffer.append("Text");

sBuffer.toString();


Good luck
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12492027
I think I was right in saying that it needed a re-write...passing 10K chars in the URL is never a good idea...
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now