How do you pass an array parameter in a .jsp file without having a very long URL?
-
I have to jsp files and I want to pass an array from the first one to the second one. I have this code: (1.jsp) <script> var wordsArr = [red, blue, green, black, white, yellow, orange]; var arrcount = words.length; window.location.replace("2.jsp?words=" + wordsArr + "&count=" + arrcount); the URL becomes "2.jsp?words=red,blue,green,black,white,… Is there another way to make the resulting URL shorter?
-
Answer:
Technically speaking, you need to use http post instead of http get. Normally that is done with a form, but it can be done entirely in javascript. This keeps the input out of the resulting url. var wordsArr = [red, blue, green, black, white, yellow, orange]; var arrcount = words.length; var myForm = document.createElement("form"); myForm.method="post" ; myForm.action = "2.jsp"; var wordsInput = document.createElement("input") ; wordsInput .setAttribute("name", "words") ; wordsInput .setAttribute("value", wordsArr); myForm.appendChild(wordsInput ) ; var countInput = document.createElement("input") ; countInput .setAttribute("name", "count") ; countInput .setAttribute("value", arrcount); myForm.appendChild(countInput ) ; document.body.appendChild(myForm) ; myForm.submit() ; document.body.removeChild(myForm) ;
chained at Yahoo! Answers Visit the source
Related Q & A:
- How do I convert a PDF file to PDF/A in Delphi?Best solution by softwarerecs.stackexchange.com
- How to Upload a JSP File to the smart FTP?Best solution by Yahoo! Answers
- How to debug a core file without debug symbols?Best solution by Stack Overflow
- How do you pass the last level in a new Super Mario on ds?Best solution by Yahoo! Answers
- How to put a video file on to a disc?Best solution by wikihow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.