WilliamN
WilliamN

Reputation: 89

How can I pass JS variable from a jsp page to another?

I have something like this in file1.jsp :

var var1 =  "a long string of 20.000 caracter";
document.getElementById('urlPop').value = var1;

Also in file1.jsp :

<form method="POST" name="urlForm" id="urlForm">
    <input type="hidden" id="urlPop" name="urlPop"/>
</form>

(When I use firebug, my hidden input is modify by my javascript as well.)

And there is a link who is maked like this :

<a href="${url_rapport}" target="_blank" style="position: relative; top: -5px; left:15px;"  onclick="document.getElementById('urlForm').submit();">Rapport PDF</a>

My link open a file2.jsp where I make this :

<IMAGEPOP><%= request.getParameter("urlPop")%></IMAGEPOP>

But it doesn't work, I don't know why... Had I forgot something ??

Thanks for help, will.

EDIT :

I had just test with an insert in my DB and in the file2.jsp "request.getParameter("urlPop")" is equal to null so the problem is here and I don't know how to solve it :/

Upvotes: 0

Views: 1065

Answers (2)

Vivek Mishra
Vivek Mishra

Reputation: 1804

I think you should use Session variable or cookies to pass that variable from one jsp page to another. you could also use Local Storage.

Upvotes: 1

Benjamin
Benjamin

Reputation: 23

I'm not really sure but, I think you forget a "action" with your form.

have you tryed something like that ?

<form method="POST" name="urlForm" id="urlForm" action="file2.jsp ">
    <input type="hidden" id="urlPop" name="urlPop"/>
</form>

Upvotes: 0

Related Questions