aspose file tools
The moose likes JSP and the fly likes get string values from Request and Session Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "get string values from Request and Session" Watch "get string values from Request and Session" New topic
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
    
  13

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
    
  13

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
    
    2

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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: get string values from Request and Session
 
Similar Threads
Passing/Accssing HttpSession to service layer
How many sessions/app - Timeout - question?
servlet version
Session Timeout
session time out cheching using filter