How can I implement session variables in J2ME?

Is it possible to use session in J2me? I am trying to develop a Blackberry application. I want to get some text from a class(page) and use in another class(page). May be something like the we do in app.net as:

Class1 { session("myVariable") = Textbox.Text; } //a new class Class2 { TextBox2.Text = session("myVariable").toString(); }

I will really appreciate for any type of help.

-------------Problems Reply------------

You can have a third class where you store such 'global' variables. You can make these variables public and static; though this can lead to tightly coupled code.

public class GlobalVariables
{
public static string MyVariable = "empty";
}

Then you can do...

GlobalVariables.MyVariable = Textbox.Text;

...and...

TextBox2.Text = GlobalVariables.MyVariable;

...anywhere in your code. While this would tend to be frowned upon in usual circumstances it can be useful when trying to write minimal, fast code to run on limited devices.

Another tip is to have a reset-method in GlobalVariables to reset all the static values back to their defaults in case the user wants to reset the app from within the app. Also, if this is the only place you will store all your per-session variables you can add RMS save and load methods in here to keep it all in one place.

Again, it's not the best way of doing things... but it is simple.

When I first saw your question I thought it was going to be about HTTP sessions, but it looks like you're just after a way of storing state in your application.

There are a number of ways to do this. Some things to consider:

  • Do you need to persist the session data (or perhaps some of it) between runs of your application?
  • Is the set of session variables fixed, or can it vary?
  • Are all variables 'stringy' or are some numeric?

A simple implementation might be an instance of Hashtable in a class with public static methods to get and set variables by calling the Hashtable put() and get() methods.

Category:java Views:0 Time:2010-02-18

Related post

  • implementing security with session variables, how it is insecure 2010-05-05

    I am doing web based projects in dotnet. Currently I am implementing security using session variables. I keep current user id and user type in session and authenticate user from these session variables (say Session["UserId"],Session["UserName"] and S

  • What to put in a session variable 2008-09-16

    I recently came across a ASP 1.1 web application that put a whole heap of stuff in the session variable - including all the DB data objects and even the DB connection object. It ends up being huge. When the web session times out (four hours after the

  • Closing the browser should actually clear the session variables an ASP.net session id 2008-11-13

    I have an ASP.net page. When I am closing the webpage I need to clear the session variables. How to to handle this I need to maintain the timeout to 20 minutes. If he closes and login for any number of times in the 20 minutes timed out time Is there

  • asp.net: moving from session variables to cookies 2009-01-13

    My forms are losing session variables on shared hosting very quickly (webhost4life), and I think I want to replace them with cookies. Does the following look reasonable for tracking an ID from form to form: if(Request.Cookies["currentForm"] == null)

  • Can I set Session timeout for a specified Session variable differently than other Session Variables 2009-01-28

    I'd like to set the timeout on a specific Session Variable in a .Net web application, but leave other Session variables alone. Is this possible? Example: I have 5 Session Variables Session(var1) Session(var2) Session(var3) Session(var4) Session(var5)

  • Session variables in ASP.NET MVC 2009-02-18

    I am writing a web application that will allow a user to browse to multiple web pages within the website making certain requests. All information that the user inputs will be stored in an object that I created. The problem is that I need this object

  • store HttpContext.Current.Request.Files in session variable 2009-04-28

    I want to store files uploaded by user in session variable,so that i can use it from any page i want in my project.i am retreiving files from statement: httpFileCollection uploads=HttpContext.Current.Request.Files; how can i store and retrieve this i

  • ASP.NET Masters: What are the advantages / disadvantages of using Session variables? 2009-04-28

    I've done a search on this subject already, and have found the same data over and over-- a review of the three different types of sessions. (InProc, Sql, StateServer) However, my question is of a different nature. Specifically, what is the advantages

  • Accessing Session variable and performance 2009-04-30

    I have a web application inside where i need to check whether the user has sufficient permissions / roles/rights to access the page. I had set the users rights in a table with USER_ID, ROLE_ID. and when a user is logging in to the application, I will

  • Struggling with acceptable use of Session variable in ASP.NET 2009-05-07

    I tried to wean myself of lopping everything in a Session variable in ASP.NET (I came from a Windows programming background), and I generally completely stopped explicitly storing anything in a Session variable. Can anybody give some guidelines as to

  • What is the maximum size a session variable can hold? 2009-11-18

    What is the maximum size a session variable can hold ? I am trying to store object in session variable, if object size is under 80 KB, then working fine and if the size is greater than 80 KB then on retereival I am getting exception. How can I increa

  • How do I use my Session variable in an if statement as an integer? 2009-12-18

    I have a Session that stores an int. I usually do the following... if(Session["test"] == null) Now that I am comparing... public ActionResult NumbersGame(int myNum) { if(Session["test"] != myNum)... How do I do that? --------------Solutions----------

  • Passing session variables to different application on different server 2010-02-24

    HI, We have two applications to be hosted on two different servers. The applications will be built in .NET3.5 and hosted using IIS. We want to share the session variables between the application which will be on different servers. Is there some way t

  • What is the accepted pattern for implementing Session in ASP.NET MVC sites? 2010-03-05

    Obviously, the typical WebForms approach won't work. How does one track a user in an MVC world? --------------Solutions------------- Session works exactly the same way it worked in Webforms. If you want to store simple information, use forms authenti

  • Problem retrieving multiple instances of the same asp.net session variable 2010-03-16

    I'm having problems with retrieving multiple instances of a session variable from an InProc session state. In the following code I persist a simple BusinessObject into a session variable on the Page_Load event. On the click of a button I try to retri

  • How do servlets work? Instantiation, session variables and multithreading 2010-06-24

    Suppose, I have a webserver which holds numerous Servlets. For information passing among those Servlets I am getting the Servlets context and setting session variables. Now, if 2 or more users send request to this server then what happens to the sess

  • Google App Engine Cache List in Session Variable 2010-07-02

    I have a question about Google App Engine java implementation. I have been trying to port over an application to google app engine from mysql/tomcat. I have changed and tested most of the code on the google app engine local environment. The applicati

  • Is it possible to "pirate" a session variable (I do not want to know how) 2010-08-09

    I am currently doing a website in php, we are using a Session variable to store the permission level of each user. For example, if any one of you would go on the website, you would automatically get a session variable with a value of "member". What I

  • Preserve Session Variables Across HttpHandlers 2010-08-19

    I have an ASP.NET application with 5 .ashx HTTPHandlers that implement IRequiresSessionState or IReadOnlySessionState. Upon calling the first handler I create a variable and store it in the session. When I call the next HttpHandler the variable is no

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.172 (s). 11 q(s)