Solved

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

Posted on 2004-08-31
3
878 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
spring dependency injection using java config 2 94
reflection example 3 131
listing all functions in JavaScript 19 252
print map entry 34 79
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Deploying our service is a grudge match between customer benefits and customer pain. In one corner, rolling out fixes (yay!) and delivering new features (double yay!). In the other corner, training on new features (boo – sounds like work), and chan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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