473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Reading session variable

hi all,

i am working on a java and HTML based web application. now i am storing
session variables. is there a way for me to pass on these variables to
javascript. what i am getting at is, i need JS to do something based on
the user variable.

can somebody help me out on this one.
thanks.

Jan 17 '06 #1
4 14806
Write it out into a hidden and retrieve it from the client. Or simply
create a javascript that contains something like:

out.println("<script>myVar=" + session.getAttribute("id") +
";</script>");

and you have the myVar variable in JS.
At least you get the ideea and can do more nicely depends on what you
are using.

Regards

Jan 17 '06 #2
Write it out into a hidden and retrieve it from the client. Or simply
create a script directly from the server that looks something like:

out.println("<script>myVar=" + session.getAttribute("id") +
";</script>");

and you have the myVar variable in JS.

At least you get the ideea and can do it more nicely depends on what
you
are using.

Regards

Jan 17 '06 #3
the second approach is a bit difficult as i am using separate HTML
pages. the first approach sounds better. but how do you implement it
and what do you mean write it out into a hidden and retrieve it. can
you help more.

Jan 17 '06 #4
If you use separate html pages in frames and so, you can simply modify
it as this.

out.println("<script>top.myVar=" + session.getAttribute("id") +
";</script>");

this will create the variable in the top (the main window object) that
is accessible from every frame by using top.myVar

The other approach would be somewhat simillar, but instead of creating
a variable you create a hidden field in the DOM and you retrieve it by
document.getElementById.

ex:out.println("<input type='hidden' id='mySessionId' value='" +
session.getAttribute("id") + "'/>");

and thus you have an object but this will create it in the same page
that has the process behind it.
You could combine with the first one I described, I presume you have a
login or something where you set all the session variables. At this
stage you can set up all these shared resources too. My advice is to
simply set at this time the top.myVar with the required id and it will
be globally available. If not, deceide on a persistent (something that
lasts and won't change) hidden frame and build thare the objects that
will have the values that you need. Be careful if storing sensitive
data like passwords etc.

Jan 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Peter | last post by:
L.S. I am developing a PHP-login script (on Lycos Tripod) that uses Session to pass on variables. Below is the entire (stripped) structure that I use. It opens a page where you can Set and Read...
0
by: Dr. Lovable | last post by:
Hidee, I'm pretty much a newbie and I'm sure most of these questions have been answered before, but humor me, okay? I keep reading that Session variables are evil things to be avoided. Is it...
14
by: Bobby | last post by:
I have this line, at this time the value of Session("Login") is 1: Response.Write "<a href=" & Request("script_name") & _ "?action=show&o=" & rsCustOrders("OrderID") & _ ">" &...
3
by: Jeff User | last post by:
Hello I am hoping someone knows the answers I seek.. I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to...
2
by: Jeff User | last post by:
Greetings I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to check to see if the Session variable has...
2
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and...
3
by: vvenk | last post by:
Hello: This was posted in a wrong forum; that's why I am posting here again. Sorry. I just wrote my first ASP.Net application, tested it on my development environment and deployed it on a...
3
by: RSH | last post by:
Hi, I have a situation where I have a page built in .Net 1.1 that I have a PlaceHolder in the Design. From the CodeBehind I am dynamically referencing a user control. This is a snippet from...
4
by: Bjorn Sagbakken | last post by:
In a web-application with login creds (user, pwd), these are checked against a user table on a SQL server. On a positive validation I have saved the userID, name, custno and role-settings in a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.