Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me.

 
Michael Zhang
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all.
I want to use JavaScript's variable in JSP block. I know JavaScript is Client-Side script and JSP is Server-Side script, so, following code is impossible, but I hope it's another way to achieve my aim. Please help me.
SCRIPT language=JavaScript>
function loadSubMenu(Value){
<% Vector term1 = teacher.getTerm(Value); //I want to use JavaScript's variable "Value"
%>
}
</SCRIPT>
 
xia zhi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no way......
it's impossible.
 
Peter Daly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the flow of things:
JSP Run -> client receives page -> JavaScript Runs
JavaScript can never talk directly to JSP, since in a Page's life, JSP is "done" by the time JavaScript starts executing.
What you want to do may be possible, but not the way you are thinking about doing it. You could load the page again (controlled by JavaScript) passing the value of the JavaScript variable as a parameter on the request. For example "mypage.jsp?field=value".
We might be able to provide more help if we knew more (from and end user perspective) what you were trying to accomplish.
-Pete
[ March 27, 2003: Message edited by: Peter Daly ]
 
Michael Zhang
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
Arron Zhang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this,
<form name="form1" action="">
<input type="hidden" name="a" value="">
</input>
<script language="javascript">
//set value of "a"
//set action of "form1"
form1.submit()
</script>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic