Solved

problem with calling a servlet from a javascript using window.location

Posted on 2004-08-31
3
865 Views
Last Modified: 2008-01-09
I am calling a servlet from a javascript using the following code:

pageUrl  = "/servlet/Main?ReportID=ADD&year=" + year1 + "&field2=" + field2 (etc, etc, etc)

location.replace('" "');
window.location = pageUrl;
return true:

i use this code all the time, but this time I am sending TONS of data, and it errors on the window.location line.  I am pretty sure it's because of the amount of data that I'm sending via the url.  I tested by limiting the amount of data and it works, but when I send all the data that is needed, it freaks out
with a javascript error that can't be captured and gives me a "page not found" error with the following in the url:

/servlet/"%20"

when it should be /servlet/Main?ReportID=ADD&year=2004&field2=field2 (etc, etc, etc)

Is there a limit to the amount of characters in a url?  And if so, how can I pass all my data to the servlet using a javascript?  Can I use putsession commands in a servlet?

HELP!


0
Comment
Question by:donz4
3 Comments
 
LVL 19

Accepted Solution

by:
ramazanyich earned 250 total points
ID: 11947803
the length of query string can vary depending on the server. Some servers end reading it from 1024 byte. In general it is not recommended to use parameters in URL if it will be a big one. Better use hidden  form with POST method and filling hidden values by javascript and calling form.submit() function from javascript.
So in your case it javascript  can be:
document.hh.ReportID.value="ADD";
document.hh.year.value="2004";
document.hh.field2.value="field2";
//...
document.hh.submit();



and HTML:
<form name="hh" method="POST" action="/servlet/Mail">
<input type="hidden" name="ReportID"/>
<input type="hidden" name="year"/>
<input type="hidden" name="field2"/>
<!-- add other input elements for other parameters -->

</form>

0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11948427
Please check this first.

pageUrl  = "/servlet/Main?ReportID=ADD&year=" + year1 + "&field2=" + field2 (etc, etc, etc)

I think there is one space in

"/servlet/ Main?......
            ^
             There is one space here!
0
 
LVL 11

Expert Comment

by:raj3060
ID: 11966676
If it is working fine with less data, then there nothing wrong with the code. I would say send data in array. That will be faster and easier.
--Raj
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Some of the SEO trends we might expect in 2017.
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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