• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

how to retrieve jsp variable in javascript

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I want to access jsp variable in javascript i have using hidden variabel but its not working can any one help me in this regard
Thanks
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you got so far?
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In short, you shouldn't access JSP variable in javascript directly. Theoretically you could create a cookie in the JSP that the javascript can then access, but I wouldn't recommend that under most conditions. If the data really needs to be hidden, I'd suggest another pattern such as calling a servlet separately.

What I would recommend is just generate code that creates a javascript variable such as 'var myJavaScriptVar = <%=myJSPVar%>;' or some variation that could then be used by the HTML/JavaScript page.
 
shahin Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
My string contains some html links like
"safdsf <a class=\"styleClass\" href = \"javascript:somemethod(HERE I HAVE NEED SINGLE QOUTE)\"";

if i include single quote thewe i won't get the value in the script if not i get the value easily
but to process further i need single qoute there Can any one help how to reslove this problem
Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you building HTML strings using Java from within a JSP page?
 
shahin Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either from java or from html there will be problem with single qoutes when the string contains it
I have resolved it by giving \\\" in place of ' and it works fine for me
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by shahin Khan:
Either from java or from html there will be problem with single qoutes when the string contains it
I have resolved it by giving \\\" in place of ' and it works fine for me



JSP eliminates the need to build complicated, nested strings like that.
Why are you still doing it the hard way?
 
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic