Storing array in session

hi guys, i need your advice , is it safe to store array in session will it use up the webserver memory ? thanks a lot

hi,
session.setAttribute("attibuteName", Object);
you can put all u need in your sesion's attributes.
get them with:
if(session.getAttribute("attributeName")!=null) variable = (variableDataType) session.getAttribute("attributeName");
for example:
vector myVector = new Vector();
if(session.getAttribute("myVector")!=null) myVector = (Vector)session.getAttribute("myVector");
hope this helps
Message was edited by:
Tobi

Similar Messages

  • I need to add the values stored in the session object into the html textbox

    Dear Sir,
    i have been trying to create an edit employee details page
    What i have done till now is as follow:
    1. Got employee id from HTML page.
    2. Compared it with the id stored in the database.
    3. If the id is correct then pulled the record of the corresponding employee and stored it in the session object.
    4. Dispatched the session values to another servlet EditEmpDetails2.java
    what i need to do now
    5. Now i need to set the session values in the text field of the html form
    6. I also need to be able to edit those vales and store the edited values in the database.
    Please help me as i have tried doing it for 1 week without any clues
    i have tried to create a html page which is something like this:
    <html>
    <head>
    <title>Edit Employee Details Page</title>
    <body BGCOLOR="red" text="black">
    <h1 ><font color="black">Edit Employee Details Page</font></h1>
    <form action = "EditEmpDetails" method="Get">
    <table width="50% align="center"
    <tr><td>Employee ID: </td>
    <td><INPUT TYPE="TEXT" name="employeeid"<br></td></tr>
    <tr><td><center><input type="submit" value="submit"></center></td></tr>
    <tr><td><center><input type="reset" value="reset" ></center></td></tr>
    </table>
    </form>
    </body>
    </html>
    design of my servlet EditEmpDetails.java
    public void EditEmpDetails1 extends HttpServlet
    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
    PrintWriter out = response.getWriter();
    response.setContentType("text/html");
    HttpSession session = request.getSession();
    String employeeid;
    String X = request.getParameter("employeeid");
    System.out.println("Employee iD:" + X);
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:murphy");
    String query = "Select * from users where employeeid=?";
    PreparedStatement stat = con.prepareStatement(query);
    System.out.println(stat);
    stat.setString(1,X);
    ResultSet rs = stat.executeQuery();
    while(rs.next())
    String Z = rs.getString(password);
    if(Z.equals(X))
    String A = rs.getString(1);
    session.setAttribute("employeeid", A);
    String B = rs.getString(2);
    session.setAttribute("firstname", B);
    String C = rs.getString(3);
    session.setAttribute("lastname", C);
    String D = rs.getString(4);
    session.setAttribute("gender", D);
    String E = rs.getString(5);
    session.setAttribute("dateofbirth", E);
    String F = rs.getString(6);
    session.setAttribute("address", F);
    String G = rs.getString(7);
    session.setAttribute("postalcode", G);
    String H = rs.getString(8);
    session.setAttribute("phone", H);
    String I = rs.getString(9);
    session.setAttribute("mobile", I);
    String J = rs.getString(10);
    String url = "/EditEmpDetao;s.java";
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url)
    dispatcher.forward(request,response);
    catch (Exception e)
    system.out.println(e)
    I do not know how to put the values stored in the session object into the html text box

    3. If the id is correct then pulled the record of the corresponding employee and stored it in the session object.do you really need to store this in session object?
    5. Now i need to set the session values in the text field of the html form which form? in a new html/jsp page? i suggest go for a JSP
    In your JSP page use JSP expression tags to put the session attributes.
    it's something like : <input type='text' name='employeeid' value='<%= session.getAttribute("employeeid") %>' >and you need to generateanother servlet for saving the details/modifications to the database.
    I think i m clear enough.
    if you need more clarifications. just try it and then post your problem.
    Diablo

  • How can i get the value stored in the session object using its sessionid

    how can i get the value stored in the session object using its sessionid by running stand alone java application

    myforum wrote:
    how can i get the value stored in the session object using its sessionid by running stand alone java applicationThis does not seem to make sense! You need at least to give a lot more detail of what you are doing.

  • How to retrieve string array using Session?

    Hi, I am having some problem retrieving string arrays through session.
    String personalData[] = new String[17];
    personalData = (String [])session.getValue("PersonalData");
    The coding above isn't working. Advise pls.. Thanks

    The getValue() method is deprecated - you should probably be using getAttribute.
    What about this code isn't working? Looks ok to me, as long as the "PersonalData" object in the session is a String[] it should work.
    Cheers,
    evnafets

  • How do I  call a DeleteAllQuery stored in the session object?

    Hi all,
    I have a DeleteAllQuery that I have stored in my session object by name (PURGE_IRLE):
    srvSession.addQuery(DaoConst.PURGE_IRLE, delq);
    I have RTFM:ed but the only description for deleteing that I could find delets individual objects. I couldn't find an example for DeleteAllQuery. :-(
    I set the reference class when I define the query but I'm confused by the getObjects() and setObjects() methods.
    Q1: When do I need to call them?
    Q2: How do I call this query?
    Q3: Which Session.executeQuery(...) should I use? (this relates to 1 & 2).
    Q4: How do I get back the number of rows deleted? execute returns an Object; can I assume it's an Integer containing the numbers of rows deleted?
    Many thanks in advance,
    Andrei Lenkei

    Ok, but this causes me some problems because:
    1) I can't really use SQL because I need a notExists subquery access on a TopLink object that represents a join (in the pre-TopLink version of the code the object was represented by a temporary table; I could put that whole select as a subquery to the subquery but that's not very elegant and would be quite inefective)
    2) This could be hundreds/thousands of row; wouldn't deleteing them 1-by-1 be extremly inefective?
    Isn't there a way i can call the DeleteAllQuery the same way TopLink would call it?
    Regards,
    Andrei Lenkei

  • Storing array(or other data structure) in a session object

    hi wise ones
    to minimise my calls to a database I would like to store the information retrieved from a ResultSet in an array and then store this in a session object, retrieving it with getAttribute("nameOfArray"); when I need it.
    I have tried to print the object contents to test what is happening but am getting a[b] [Ljava.lang.String;@11d646c[/b] response which is something, but not what I expected.
    Is using a session the right way to make the information available to all servlets? If not what other method is appropriate?
    thank you

    thanks for your comments Annie & MLRon. I have tried both suggestions but am still hitting problems
    the usual method to get the elements results in my compiler complaining that sessionINFO is an object and .length cannot be applied to an object.
    for (int i = 0; i < sessionINFO.length; i++) {
                       out.print(sessionINFO);
                   out.print("<BR>");
    An array IS an object though?
    I have used Arrays.asList(sessionINFO) and get another compiler error stating that java.util.Arrays cannot be applied to an object
    I took my variables from the ResultSet and converted them all to Strings and put them into a String array
    int bankIDLogin=customerResults.getInt("id");
                                   //convert to String for array
                                   String bankIDLoginSTR = String.valueOf(bankIDLogin);
                                  String passwordLogin =customerResults.getString("password");
                                  String accNo=customerResults.getString("number");
                                  float accBal=customerResults.getFloat("balance");
                                  //convert to String for array                              
                                  String accBalSTR = String.valueOf(accBal);
                                  //put info into array
                                  String[]customerDetails={bankIDLoginSTR,passwordLogin,accNo,accBalSTR};then I put that array into the session object
                        HttpSession session =req.getSession(true);
                        session.setAttribute("id",bankID);
                        session.setAttribute("customerdetails",customerDetails);In a separate servlet I called the session object
    Object sessionINFO = session.getAttribute("customerdetails");How can I get the original array out of this object?
    What should I do if more than one result set is created and I need to create two session objects with customer details, (one customer has two accounts)? multi dimensional array?

  • Calling stored procedure from session bean method

    I have a situation like this :
    I have one method on a stateless session bean (and I mark this method as container managed transaction). For database related stuff, I am not using entity beans, I am using my own layer of OR mapping. This method does a lot of stuff and it involves many trips to the database, as a result of which the performance is very poor. I have identified certain pieces of functionality from this method which I think can be moved to stored procedures, while some of the functionality can still remain in the session bean method. So my scenario is like this :
    session bean method start
    store some data in tables(using my OR layer)
    call the stored procedure
    session bean method end
    My question is :
    Will the data that I am storing in tables from within the session bean method, be available to the code executing inside stored proc.
    secondly, how do I sync the transcation which is being initiated by the container with the transaction under which the stored proc is executing or is it that the stored procedure code will also be executing under the container managed transcation.
    Thanks
    Vimal

    Hi Vimal,
    Will the data that I am storing in tables from within
    the session bean method, be available to the code
    executing inside stored proc.There's only one way to find out (isn't there?)
    secondly, how do I sync the transcation which is
    being initiated by the container with the transaction
    under which the stored proc is executing or is it
    that the stored procedure code will also be executing
    under the container managed transcation.Again, why not just "suck it and see!"
    [Or is there some reason why you can't?]
    As I interpret the EJB specification, if the transaction attribute for your session bean method is such that it starts a transaction, then that transaction will be terminated when the method completes -- and every operation that occurs within the framework of that method will be in the one transaction.
    In other words, your database stored procedure should execute within the same transaction as your O/R mapping layer.
    However, how OC4J behaves may not exactly follow what is written in the (EJB) specification. Hence I repeat, "try it and see for yourself".
    Put it this way: as far as I know, the only way that your stored procedure would NOT see the changes made by your O/R mapping layer is if they both executed in separate transactions and the O/R mapping layer did not commit its changes before the stored procedure began its execution.
    Hope this has helped.
    Good Luck,
    Avi.

  • Using arrays in Sessions

    Hi! Im setting some ints inside an array for further usage.
    This is page1.jsp
    <%
    int[] page_IDS = {17,19,24,31,50};
    session.setAttribute("sessPageIds",page_IDS);
    %>
    This is page2.jsp
    <%
    out.println(session.getAttribute("sessPageIds"));
    %>The problem is that when user goes to page2.jsp, this is what gets printed:
    *[I@9d77c2*
    I would really need to sweep the original array on page2.jsp, something like:
    <%
    for(int j=0;j<session_array_name_here.length;j++){
    //check some things with the value here
    %>
    How can i retrieve the original array values? Is there a way to use the session value as an array?

    You did retrieve the original array there. But printing an array (which is what you did there) just calls its toString() value, which doesn't produce anything useful. You could write a loop that looked at each of the individual elements.
    Some advice on JSP: scriptlets like that are obsolete. You should be using JSTL rather than just inserting clumps of Java code.

  • Storing Array of Floats as a BLOB

    I am designing a new laboratory database. For some tests, I have several waveforms with ~10,000 data points acquired simultaneously. In the application (written in C), the waveforms are stored as an array of floats.
    I believe I would like to store each waveform as a BLOB.
    Can the data in a BLOB be structured in such a way that Oracle can work with the data itself using only SQL or PL/SQL?
    * Determine max, min, average, etc
    * Retrieve index when value first exceeds 500
    * Retrieve 400th number
    * Create BLOB which is a derivative of first BLOB

    Let me start from your last question should I use BLOBS?, the answer is simple - NO, why the hell do you need to store is on BLOB's, you are talking about 6,000,000 rows per day it avarag no more, uses reular tabular reprisentitiona and you will be able to query the data properlly.
    1. If I decide to use a BLOB then the calculations must be performed in the application. Correct? - Yes
    2. In order to query on data derived from the raw data, the result of any calculations must be re-inserted into the database. Correct? - Not exacly.
    3. Considering the quantity of data and how I want to use it, should I use BLOBS? - Regulat tabular represintition, and you can archive the data after X day or use summery tables.

  • Problem when passing string array in sessions showing null value

    i am trying to pass a string array but it is showing me the null value
    i think the the problem is seem to be in session.settAttribute("subject['"+i+"']",subject) in 2.login_action.jsp
    or in String sub1=(String) session.getAttribute("subject[0]"); in 3.user_home.jsp
    i have following three pages
    1.login.html
    2.login_action.jsp
    3.user_home.html
    1.login.html
    <html>
    <body>
    <form method="post" action="login_action.jsp">
    Username<input type="text" name="username"></input>
    <br>
    Password<input type="password" name="password"></input>
    <input type="submit" value="login"></input>
    </form>
    </body>
    </html>
    2.login_action.jsp
    <%@ page contentType="text/html"%>
    <%@ page import="java.sql.*" %>
    <%!
    String user,pwd;
    String subject[]=new String[10];
    int i,totalsubject;
    %>
    <%
    try
    user=request.getParameter("username");
    pwd=request.getParameter("password");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:ods","scott","tiger");
    PreparedStatement ps = con.prepareStatement("select password from users where username='"+user+"'");
    ResultSet rs = ps.executeQuery();
    if(rs.next())
    if(rs.getString("password").equals(pwd))
    session.setAttribute("username",user);
    PreparedStatement ps2 = con.prepareStatement("select subject_id from allot_teachers where staff_id='"+user+"'");
                        ResultSet rs2 = ps2.executeQuery();          
                             while(rs2.next())
                             i=0;
                             subject[i]=rs2.getString(1);
    // if i display here the subjects in out.println(subject[i]) it is working fine
    // but in next redirected page it is showing null
                             session.setAttribute("subject['"+i+"']",subject[i]);
                             //out.println(subject[i]);
                             i++;
    response.sendRedirect("user_home.jsp");
    else
    out.println("error invalid username or password");
    else
    out.println("error invalid username or password");
    con.close();
    catch(Exception e)
    out.println(e);
    %>
    3. user_home.jsp
    <%@ page contentType="text/html"%>
    <%@ page import="java.sql.*" %>
    <html>
    <%
    String user,pwd,cat,cat1;
    String username=(String) session.getAttribute("username");
    if(username==null)
    response.sendRedirect("login.html");
    //just tried for first two subjects
    String sub1=(String) session.getAttribute("subject[0]");
    String sub2=(String) session.getAttribute("subject[1]");
    //here it is printing null
    out.println(sub1);
    //here it is printing null
    out.println(sub2);
    %>
    <form method="post" action="logout.jsp">
    <input type="submit" value="Logout"></input>
    </form>
    </html>
    Cheers & Regards
    sweety

    The name in getAttributre doesnt match the name in setAttribute.
    Note "subject[0]" is a string containing 10 chars, "subject" is a string containing 7 chars.
    Here is your code:
    session.setAttribute("subject",subject);
    String sub1=(String) session.getAttribute("subject[0]");

  • Storing array elements

    I'm running quite a big application. I'm storing data in an array what I find that that while the application is running the value of the elements inside the array is not releasing even though the idex of the element is already passed to the next one. Hoever the values of the elements inside the array will be showed after the application is complete. This is not what I want I want to show that index array is the application taking the data from at the moment and what value of the data. How can I see those current values instead of seeing them after the application is completed?

    There's probably probably something in your code that prevents the array from being updated straight away.. My guess is that it's a data flow problem. Let's say e.g. that the array you are looking at is wired to the output of a VI, a shift register, or through the side of a loop, case or sequence...then the array does not really receive the new data until everything inside that structure (VI/loop etc...) is finished running. LabVIEW does not release the data coming out of such structures until all outputs of that structure is ready...so you need to put the indicator inside that "border" or use a local/global (functional) to see the data on the fly...
    If you could take a picture of the code; showing the array terminal /wires and the data source ...or a copy of the VI(s
    ) that would help pin-point the problem.
    MTO

  • Storing array of single bits

    Hi, I have an object in my application which is hogging memory as there is up to 3million
    of them in memory at one time and i am trying to cut down the size of it.
    the core data structure is an array of 1's and zero's.
    currently i'm using a byte[] to store these.
    Because i know i only ever want to store a 1 or a 0 at each index, is there a way of storing
    these as a boolean[] {1bit of storage in my understanding} so that i can save memory

    Here's an example of packing 8 of your bytes from the array into a byte, then unpacking it into a String.
            byte[] ba        = {0, 0, 1, 0, 1, 0, 1, 0};
            // when packed into a byte the array value is decimal 42
            //Pack a byte
            byte packedByte  =
                (byte) ((byte) ((ba[0] & 0xf) << 7) |
                        (byte) ((ba[1] & 0xf) << 6) |
                        (byte) ((ba[2] & 0xf) << 5) |
                        (byte) ((ba[3] & 0xf) << 4) |
                        (byte) ((ba[4] & 0xf) << 3) |
                        (byte) ((ba[5] & 0xf) << 2) |
                        (byte) ((ba[6] & 0xf) << 1) |
                        (byte) ((ba[7] & 0xf) << 0));
            System.out.println("The byte value is " + packedByte);
            //Unpack a byte
            String UnpackedByte = Integer.toBinaryString(packedByte);
            System.out.println("The binary string is " + UnpackedByte);

  • Storing arrays in a single file!!

    Hello all,
    Is it possible to store two arrays into a single file either separately or together as a POJO. How to accomplish this??..Need some guidance

    try DataInputStream and DataOutputStream
    ObjectInput/OutputSTream is used to store Object which use more space.

  • MYSQL JSP  Storing array to a database

    I have an combobox by which multiple values can be selected. I need to store the values available in the combo box into mysql database as an array in the database.
    eg:
    If I select one,two,three,four as values for the number field
    then in the db it should be shown like this
    name | values
    number | one
    | two
    | three
    | four

    Ok here is the sample code
    Table in db
    mysql> create table test (a INT NOT NULL, b SET('USA', 'India', 'Pakistan', 'Russia'));
    First.htm (say)
    <html>
    <body>
    <form name="frm" action="Test.jsp" method="post">
    <input type=text name="na" >
    <select size="1" name="a8" tabindex="7" multiple>
    <option>India</option>
    <option>USA</option>
    <option>Russia</option>
    <option>Pakistan</option>
    <input type="submit" name="abc" value="ok">
    </form>
    </body>
    </html>
    First.jsp
    <%@ page language="java" import="java.sql.*"%>
    <html>
    <head>
    <title>Testing SET in MySQL</title>
    </head>
    <body>
    <%
    String arr[] = request.getParameterValues("a8");
    String strToInsert = "";
    for(int i=0; i<arr.length; i++) {
    if(i==arr.length-1) {
    strToInsert += arr;
    } else {
    strToInsert += arr[i] + ",";
    out.println(strToInsert);
    String strID = request.getParameter("na");
    int iID = Integer.parseInt(strID);
    Class.forName("Driver");
    Connection con = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/dbName?user=username&password=password");
    Statement stmt = con.createStatement();
    stmt.executeUpdate("insert into test values("+iID+", '"+strToInsert+"')");
    %>
    </body>
    </html>
    I assume that int value will be sent in text filed named "na".
    Above file will insert record in db.....

  • Safari storing previous secure session data in plain text.

    I was just forwarded a link stating that Safari stores previous secure session data unencrypted in a hiodden folder. The article said this applies to OS X 10.8.5,and OS X 10.7.5 running Safari 6.0.5. Has this vulnerability been fixed in Mavericks/Safari 7.0?
    http://securityaffairs.co/wordpress/20482/hacking/safari-unsecure-data-storage.h tml

    It's not the transit that I'm asking about, but a secure local session with private info in a hidden folder. If another user gains access to this hidden folder, then private info can be disclosed (i.e., passwords, address).

Maybe you are looking for