Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

19 Experts available now in Live!

Get 1:1 Help Now