• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to use Javascript variable value in JSP

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any one tell how to use java script varaible value in JSP.

Here code looks like....

<script type="text/javascript">
var test1=window.location.pathname
</script>

How can i use this "test1" in my jsp/jstl code.

Test path is <c:out value='${test1}'>

how can print Scriplet genrated result in JSTL.


Thanks
cheers....
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSPs run at the server, while JavaScript runs at the client - never the twain shall meet.

The JSP already knows the URL of the page it's generating - what else are you looking for?
 
sourabh bansal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:JSPs run at the server, while JavaScript runs at the client - never the twain shall meet.

The JSP already knows the URL of the page it's generating - what else are you looking for?





Thanks Sherrif....Thanks for the reply,I want to use in tracking purpose...Is there any other way to do it....




 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The title here : http://www.jguru.com/faq/view.jsp?EID=22950
is

How can you copy a JavaScript variable to a JSP session variable without using cookies?


so there's an answer for you.

Try generating / editing a JSP page from JavaScript:
http://www.java2s.com/Code/JavaScript/HTML/HTML-Generate.htm
http://www.java2s.com/Code/JavaScript/HTML/UsingJavaScripttoCreateHTMLTags.htm
If you can generate HTML you can generate JSP IMO (or at least try resending the page with JSP markup to the server, if you can do that it'll work).

You can say you use a javascript variable in JSP too if you use it before the javascript is used :P - before you generate it that is.
http://coldjava.hypermart.net/servlets/jscalltag.htm
http://www.ibm.com/developerworks/web/library/wa-aj-simplejava1/index.html
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tudor Andrei Raneti wrote:If you can generate HTML you can generate JSP IMO


Ummm, no. You can't. Any JSP syntax generated on the client will just be gibberish.

JSP and JavaScript cannot directly interact as the JSP gets executed on the server long before the HTML page it generates is sent to the browser where the JavaScript is evaluated.
 
Tudor Raneti
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're right, I know JSP has to be parsed, and for that it needs sending to the server. The scenario i was thinking is the following: the problem is that the JSP on page is only temporary, so making a page refresh or self forward to self would return the old version of the page i think (because the server still has the old version, so a request will send the old version as a response). The chalange would be sending the new page as it is to the server and getting the parsed version of it back . It's beyond me at this point. Probably would need a special framework to do that, but i don't see the point.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no point as all that is not necessary in the face of techniques like Ajax. What the original poster needs to understand is how JSP really works and why what he's trying to do makes no sense and is non-causal.

Then he can post what he's really trying to accomplish and we can all figure out the best way to get it done.

Perhaps this article can help.
 
Oh. Hi guys! Look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic