I am currently facing a requirement where I need to transfer a value from JavaScript to a Scriplet in a JSP. Despite being aware that JavaScript runs on the client side and JSP on the server side, I have been unsuccessful in finding a suitable solution for this issue even after extensive online research. Both JavaScript and scriplet codes are included within the same JSP file.
<script type="text/javascript">
var strUrl = window.location.href;
var aps = strUrl.toLowerCase().indexOf("values");
var modifiedString = strUrl.substring(aps+8);
var v = strUrl.indexOf(modifiedString);
document.write(v);
</script>
<%
String st="<script>document.writeln(v)</script>";
out.println("-----"+st);
int pareseValue = Integer.parseInt(st);
if(st.equals("0")){
out.println("test");
%>
<h1><div class="xyz">
<fmt:message>header.txt</fmt:message>
</div></h1>
<%
}else{
%>
<div class="pqr">
<fmt:message>header1.txt</fmt:message>
</div>
<%
}
%>
The code above shows my attempt to pass a value from JavaScript to a scriplet. However, when trying to parse and convert the string into an integer, I encounter a NumberFormatException. It seems that the variable 'st' is not of a string type.
String st="<script>document.writeln(v)</script>";
out.println("-----"+st);
int pareseValue = Integer.parseInt(st)
I am seeking guidance on identifying the problem with the code and resolving the issue at hand.
Thank you, Vikeng