Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 4323
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?
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic