Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Assigning jsp expression value to javascript variable  RSS feed

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1)how to Assign scriptlet code (JSP expression code) to javascript varaible

Below code gives error? Please help


<code>
<script>
function checkButtons()
{

String viewCode ="<%=(request.getParameter(TMConstants.TM_VIEW_CODE))%>"

alert("viewCode");




}
</script>

</code>
 
K Kiran Kumar
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think we can access the java variables directly inside the javascript.
However you can try out the following....
(1) Create a hidden variable
<html:hidden property="getcontext" value="<%=request.getContextPath()%>"/>
(2) Access the same using the document object
var param = document.formName.getcontext.value; //don't use String here. Use var as datatype.

Regards,
Kiran.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by amolpalekar kadolkar:
Below code gives error?

What error?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K Kiran Kumar:
I don't think we can access the java variables directly inside the javascript.
We can't, but that's not what he's doing. He's just using a scriptlet expression to insert a value into the JavaScript template text, which should be just fine.
 
Hongli Li
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you mean

instead of

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!