admin管理员组文章数量:1336660
I have the following scenario
<select name="dropdown_Source" onchange="call()">
<% for (int i=0 ; i < a1.length; i++) { if (a1[i]==n ull) break; %>
<option value="<%=a1[i]%>">
<%=a1[i]%>
</option>
<% } %>
</select>
<script>
function call() {
var source = document.forms[0].dropdown_source.value;
// Now this 'source' value i have to pass to jsp function
<%
Admin a = new Admin(); //this is class defined
a.getResult(source); //but source is not resolved here
%>
}
</script>
How this source
value should I pass in JSP function?
a.getResult()
- function will return me list of dropdown elements and that list
I have to populate in another <option>
tag.
I have the following scenario
<select name="dropdown_Source" onchange="call()">
<% for (int i=0 ; i < a1.length; i++) { if (a1[i]==n ull) break; %>
<option value="<%=a1[i]%>">
<%=a1[i]%>
</option>
<% } %>
</select>
<script>
function call() {
var source = document.forms[0].dropdown_source.value;
// Now this 'source' value i have to pass to jsp function
<%
Admin a = new Admin(); //this is class defined
a.getResult(source); //but source is not resolved here
%>
}
</script>
How this source
value should I pass in JSP function?
a.getResult()
- function will return me list of dropdown elements and that list
I have to populate in another <option>
tag.
- ugly code.. I dont know jsp but I am sure this will not work because jsp server-side javascript client-side.. If you can get dropdown value with jsp do it.. With asp I can get value of dropdown which I set its value from javascript. – Mehmet Commented May 11, 2013 at 12:33
3 Answers
Reset to default 3You cannot do that. JavaScript executes on the client side after JSP page is already piled and sent to the browser as response
.
You can not mix javascript and java code. when you do
<%
Admin a = new Admin(); //this is class defined
a.getResult(source); //but source is not resolved here
%>
This means that code snippet will be processed at server side as this is plain java code.Now variable "source" is not java variable but a javascript variable which will e into picture when your html page loads on browser. So its a pilation error.
The best thing to do here is, once the javascript executes, take that source value and make an AJAX call to your server, process it and send the values back to the client and then populate your dropdown.
本文标签: Passing a variable value from javascript to JSPStack Overflow
版权声明:本文标题:Passing a variable value from javascript to JSP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742417968a2471085.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论