Assign javascript variable to jsp variable

Struct with the below scenario ? ,

String version ="<script>document.write(get_version);</script>";
out.println(version); -------> 1.0

but version = "<script>document.write(get_version);</script>" still and are you unable to use the version variable in JSP and want to fix this issue.

Guys am here to help you out even in this tough situation. You should not suffer as I suffered to fix this issue. Please follow the below steps and make yourself great and fix the issue. Everything is possible in Java.

Assign javascript variable to jsp variable, or use javascript variable to jsp variable or pass hidden value to JSP page from another page where you are uploading a file with post method and still you want to pass a html element value from post form where you want the get method logic. Here below the great example. Try to understand the below scenario and your issue is fixed.

Current JSP or HTML form page : 

Currentpage.jsp

document.getElementById("myForm").submit();
document.myForm.action = "uploadget.jsp?hiddenVersion="+document.getElementById("version").value;
alert("File Uploaded Successfully");


 <form name="myForm" enctype="multipart/form-data" method="post" onsubmit="return validateForm();" id="myForm">
 <input type="hidden" name="hiddenVersion" id="hiddenVersion" value="">
.....
<input type="text" id="version" name="version">
......
</form>


And in your action JSP use this,

request.getParameter("hiddenVersion");

and thats it.

1 comment:

My Profile