简体   繁体   English

如何将js变量从jsp页面传递到另一个页面?

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

I have something like this in file1.jsp : 我在file1.jsp中有这样的内容:

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

Also in file1.jsp : 同样在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.) (当我使用Firebug时,我的隐藏输入也将由我的JavaScript进行修改。)

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 : 我的链接打开了一个file2.jsp文件,我在其中创建:

<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 :/ 我刚刚在数据库和file2.jsp中进行了插入测试,“ request.getParameter(“ urlPop”)”等于null,所以问题出在这里,我不知道如何解决:/

I think you should use Session variable or cookies to pass that variable from one jsp page to another. 我认为您应该使用Session变量或cookie将该变量从一个jsp页面传递到另一个。 you could also use Local Storage. 您还可以使用本地存储。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM