I want to pass a javascript variable to a jsp scriptlet (both are in the same jsp only). I tried the following.
enter code here
<html>
<script language="javascript" type="text/javascript">
function submit($i) {
var url=$i;
document.write("url is"+url); //giving me selected url and displaying on browser
window.location.replace("view.jsp?url="+url);
}
</script>
<form method="get" action="/UrlServlet">
<select name="url" id="url" onchoice="submit(value);">
<c:forEach var="dataList" items=${dataList}>
<option value="${dataList.url}">${dataList.url}
</c:forEach>
<%
String name=request.getParameter("url");
out.println(name);//giving me null as output
}
%>
</html>
It is giving a null value when I print name. Can you please tell me what was wrong? When I print $i
value in javascript it is giving me the url name from dataList. Here dataList is a list returned from my servlet. It is giving correct values only. But when I select one url from the drop down list it is giving me null at request.getParameter()
. Please, can someone help me?
I tried this
<%String st="<script>document.writeln(v)</script>;"
in scriptlet instead of window.location.replace()
in javascript. Then also I am not getting url value using getParameter, instead I am getting same statement <%String st="<script>document.writeln(v)</script>
as output.
Please do help.