| Author |
get string values from Request and Session
|
ben oliver
Ranch Hand
Joined: Mar 28, 2006
Posts: 369
|
|
|
In my jsp, I have some javascript, is it possible for me to get string variables set in Http Request and Session in my javascript ? If yes, can you show me the syntax ? Thank you.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
Not with JavaScript. JavaScript is a client-side mechanism.
That's what JSP is for -- to inject server-side values into the HTML page before it gets sent to the browser.
If you need the value on the client, then you use JSP to create the JavaScript markup to capture the data. For example:
This gets evaluated on the server and the HTML page with the value injected is what is sent to the browser.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
|
You may benefit from reading this article.
|
 |
ben oliver
Ranch Hand
Joined: Mar 28, 2006
Posts: 369
|
|
Bear, don't really get how you tied the jsp variable value to javascript var.
Can you elaborate the above syntax ? If I ahve jsp varible
<% String s = request.getParamater("ABC"); %>
How do I assign this "s" to a javascript variable ?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
That's an expression in the JSP Expression Language (commonly known as EL). Are you not using EL in your JSP programming? The answer to your specific question is this:
Don't omit the quotes; you want this to produce something like
in the HTML you're generating.
|
 |
 |
|
|
subject: get string values from Request and Session
|
|
|