Solved

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

Posted on 2004-08-31
3
888 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Gain an elementary understanding of Blockchain technology.
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

707 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