Showing session data on new servlet

I am writing a java servlet and trying to bring session information to another servlet screen in order to edit the data. When I bring up the fields on the screen the session data does not show. Here is a copy of the java program.
public void doPost( HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
res.setContentType("text/html");
PrintWriter out = res.getWriter();
HttpSession session = req.getSession(true);
if(session == null)
System.out.println(" No record found.");
else
String memberID = (String)session.getAttribute("memberID");
System.out.println("Record found in modify. " + memberID);
out.println("<jsp:useBean ID=\"memberID\" CLASS=\"Member\"/>");
out.println("<jsp:SetProperty NAME=\"setMemberID\"PROPERTY=\"memberID\" />");
out.println("<html>");
out.println("<head>");
out.println("<title>Member Modify</title>");
out.println("</head>");
out.println("<body ONLOAD=\"dynAnimation()\">");
out.println("<p ALIGN=\"center\" STYLE=\"border: 4px ridge #FFFF00; \">");
out.println("<font SIZE=\"5\" FACE=\"BookmanITC Lt BT\">MEMBER MODIFY</font></p>");
out.println("<form METHOD=\"POST\" ACTION=\"http://localhost:8080/servlet/PetShop.membermodify\" " +
"ONSUBMIT=\"location.href='_derived/nortbots.htm';return false;\" NAME=\"FrontPage_Form1\" " +
"WEBBOT-onSubmit=\"return FrontPage_Form1_Validator(this)\">");
out.println(" <p ALIGN=\"center\"> </p>");
out.println(" <p> </p>");
out.println(" <p ALIGN=\"left\"> " +
" & nbsp; Member ID: " +
" <input TYPE=\"text\" NAME=\"memberID\" value='<%=req.getParameter (\"setMemberID\")%>'" +
"SIZE=\"20\" MAXLENGTH=\"20\" TABINDEX=\"1\" />");
I've also tried:
value="<%=setMemberID%>"
But I either get no data or the expression I put in. I also did a system.out.println to see if the session data is there and it is.

String memberID =
(String)session.getAttribute("memberID");
System.out.println("Record found in modify. " +
memberID);
value='<%=req.getParameter (\"setMemberID\")%>'"
I've also tried:
value="<%=setMemberID%>"
But I either get no data or the expression I put in.try memberID instead of setMemberID
(as in value="<%= memberID %>" or request.getParameter("memberID") )

Similar Messages

  • How the hell does a person share session data between JSP page and a Servle

    1. How the hell does one share session data between a servlet and a JSP page without using a bean but rather using a normal string variable.
    2. When using session scope to access a bean the application complains about not finding the bean on the specified scope, however when I use an application scope the save the same bean, the application does find it.
    Please help!!!!!!!
    SERVLET:
    HttpSession session = request.getSession(true);
    ServletContext servletContext = session.getServletContext();
    customerID = result.getString("CustomerID");
    userName = result.getString("UserName");
    session.setAttribute("UserName",userName);
    session.setAttribute("CustomerID",customerID);
    System.out.println("Customer UserName = " + session.getAttribute("UserName"));
    response.sendRedirect("/economics/subscriptions/default.jsp");
    JSP PAGE:
    <?xml version="1.0" encoding="UTF-8"?>
    <jsp:root xmlns:jsp=http://java.sun.com/JSP/Page mlns:c="http://java.sun.com/jsp/jstl/core" xmlns:sql="http://java.sun.com/jsp/jstl/sql" version="2.0">
    <jsp:directive.page isThreadSafe="true" session="true" contentType="text/xml"/><jsp:output omit-xml-declaration="false"/><jsp:scriptlet>response.addHeader("x-xslt-nocache", "true");</jsp:scriptlet><pml>
    <page type="web" search="y">
         <pageName>Commercial Banking</pageName>
         <jsp:directive.include file="/economics/header.inc"/>
         <jsp:directive.include file="/login.inc"/>
         <jsp:directive.include file="/economics/leftMenu.inc"/>
         <!--<jsp:useBean id="UserName" type="java.lang.String" scope="session" />-->
         <content>
         <searchSum>Commercial - Main Content</searchSum>
         Value = <c:out value="${request.session.getAttribute("UserName")}"/>
         </content>
         <jsp:directive.include file="/economics/rightNav.inc"/>
         <jsp:directive.include file="/footer.inc"/>
    </page></pml></jsp:root>

    For a start, just "session" instead of "request.session" would work better. But why did you post this here and not in the JSP forum? Doesn't seem to have anything to do with Java programming.

  • Access to Users Session data in a Filter

    Is there a way to get access to a user's session data inside a Servlet Filter? I see you have access to the Servlet Context, but that doesn't include the getSession() function. How would I do this?
    Thanks

    Its pretty straight forward to get the session from a filter
    public void doFilter(ServletRequest request,ServletResponse response, FilterChain chain){
    HttpServletRequest req = (HttpServletRequest) request;
    HttpSession session = req.getSession(true);
    }

  • I just put a solid state hard drive in my mac book pro and used super duper to copy the hard drive and move the data over to thew new ssd, but most of my music isn't in iTunes when I turned it on? How do I get my music to show up in my new drive?

    I just put a solid state hard drive in my mac book pro and used super duper to copy the hard drive and move the data over to thew new ssd, but most of my music isn't in iTunes when I turned it on? How do I get my music to show up in my new drive?

    Many thanks lllaass,
    The Touch Copy third party software for PC's is the way to go it seems and although the demo is free, if you have over 100 songs then it costs £15 to buy the software which seems not a lot to pay for peace of mind. and restoring your iTunes library back to how it was.
    Cheers
    http://www.wideanglesoftware.com/touchcopy/index.php?gclid=CODH8dK46bsCFUbKtAod8 VcAQg

  • Active sessions showing no data in pie-chart

    Hi All,
    Does anyone know why my Enterprise Manager cosole in Oracle 10g installed on windows xp professional is not showing any data? Availabilty is always 0% for the instance ORCL and the active sessions pie-chart is always showing 0.01 since May 17,2005.
    Can anyone tell me how to configure EM so that instance ORCL and the active sessions start showing data again?
    Thanks

    What errors were you seeing in the log files, i am experienceing the same issue but the listener appears to be fine.

  • Passing session data between jsp and servlet

    I have a servlet that I pass data to my jsp.
    I do a session.setAtrribute in the servlet. No problem.
    I get the data no problem in the jsp that I call.
    How do I pass this same data to the another servlet?
    I basically have an array of values that I already have in the existing jsp that has been set in session.
    When I call the secondary servlet, I don't have anything in this session variable related to my array.
    Prior to posting to my next servlet, do I need to do another setAttribute inside the jsp to get the data passed to the servlet?
    Thanks.

    Two different things. The encoding adds this to the URL (after the page, before the query string
    ;jsessionid=ABC123 but only if the user isn't using cookies.
    So in your example, you would do this (maybe):
    <%
      String url = response.encodeURL("Servlet");
    %>
      <form name="form1" method="post" action="<%= url %>?cmd=pay"> ... Or some modification.
    So the difference between encodeing and using a post is that
    1) encoding adds the jsessionid to the url string if necessary. It does nothing else
    2) POSTing will send a request to the provided URL via the POST method, including the inputs of the form as parameters to the URL.
    They really don't interact with each other. It is like asking what is the difference between the Color Orange and thr Size Big? They can both be applied to the same thing, or not... and have no real relation to each other.

  • Retrieving session data in JSP  which is forwarded from a servlet

    I'm trying to retrieve session data which is set in a servlet and pass to a jsp. But its returning NULL . The session IDs are equal.
    Scenario:
    JSP display the checkbox, user selects it and submits to a servlet. the servlet display the selected items and stores the data in session.
    when the user press back button in servlet all i want to do is display those checked box which were selected before as checked in the JSP so that user can edit.
    Following is a small test code
    JSP
    <html>
         <head>
              <title>Item List</title>
         </head>
         <body bgcolor="#fedeab"><br><br><br>
         <p align=center>
              <font size=4>
              Choose the item you want!!!
         </p>
         <form action="/demo/showitem" method="post">
              <%=session.getId()%>
              <div align=center>
              <fieldset style="width:250px">
              <legend style="text-align:center">List of item</legend> <br>
              <%     
                   if (session.getAttribute("book1")!=null) {
              %>
                   <input type="checkbox" name="book1" value="book1" checked > Book 1 <br>
              <% } else {%>
                   <input type="checkbox" name="book1" value="book1" > Book 1 <br>
              <% }%>
              <input type="submit" value="Enter">
              </fieldset>
              </div>
         </form>
         </body>
    </html>               
    Servlet
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ShowItem extends HttpServlet
         public void doPost (HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
              HttpSession session = req.getSession(true);
              res.setContentType("text/html");
              PrintWriter out = res.getWriter();
              out.println(session.getId());
              out.println("<br>");
              out.println("<form>");
              String book1 = req.getParameter("book1");
              session.setAttribute("book1",book1);
              if (book1 != null)
                   out.println ("1." + book1 +"<br>");
                   out.println("<br><br><input type=\"submit\" name=\"buy\" value=\"Buy\">");
              else
                   out.println("No item to display<br>");
              out.println("&nbsp&nbsp<input type=\"submit\" name=\"back\" value=\"Back\">");
              out.println("</form>");
              RequestDispatcher page = getServletContext().getRequestDispatcher("/jsp/litemlist.jsp");
              if ((req.getParameter("buy"))!= null)
                        page.forward(req, res);
              if ((req.getParameter("back"))!= null)
                        page.forward(req, res);
         public void doGet (HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
              doPost(req,res);
    }

    req.getParameter("book1") is not NULL and returning the value of the checkbox "book1". The problem occurs when the back button is press and try to retrieve the session value in the JSP. At that time, session.getAttribute("book1") returns NULL.
    But if i convert the servlet to JSP then everything is working fine.
    So i wanted to know if there is anything wrong in the way i store the session value in the servlet and forwarding to the JSP.
    Thanks

  • Servlet Session data being shared

    I have a bunch of servlets tha basically generate reports. The problem I'm having is that when two users run the same servlet at about the same time, one of the reports will be over written by the data of the other report. It almost seems that the users are sharing the same context.
    Is there any way to fix this or do you have ny suggestions, tips as to how to prevent this.
    Thnaks in advance for any help you may provide.

    I ran into a similar problem not to long ago with sessions. I had an instance or global reference to the session object in my servlet. When two or more people used the servlet at just the right time I would get problems where data was getting used across sessions. For example:
    public class FooServlet extends HttpServlet
         HttpSession session;
         doGet(HttpServletRequest req, HttpServletResponse res)
              session = req.getSession(false);
              doStuffWithSessionData();
         doStuffWithSessionData()
              String temp = session.getValue("temp");
              //do some stuff
    }So, person A would connect to the servlet, and their session would be retreived, and the instance reference would get set to their session. Person B would connect at about the same time, their session would get retreived and the instance reference would get set to theirs... right before the getValue("temp") on person A's session is called. So, whatever I was doing for person A would end up using the data out of person B's session. I like to call this a race condition.
    It is important to keep in mind that servlets are accessed by multiple threads concurrently, so you need to make sure your servlets are thread safe. Instance variables that get modified with each request are a very bad, non-thread safe thing and will cause odd behaviour like what you are describing. I speak from experience.
    I fixed the above by removing the instance reference and doing the following:
    public class FooServlet extends HttpServlet
         doGet(HttpServletRequest req, HttpServletResponse res)
                   doStuffWithSessionData(req);
         doStuffWithSessionData(HttpServletRequest req)
              HttpSession session = req.getSession(false);
              String temp = session.getValue("temp");
              //do some stuff
              //NOTE: this works most of the time. However, if the client
              //connects with more than one browser window using the same
              //session, I could run into some trouble here too.
    }That was a quick fix. However, what I really need to do is create a separate class to encapsulate all user session data and access the session and all data through public static synchronized methods on that class, passing it the request object when I do it. That way all data is stored in one object, and that object is used to do all session access in a thread-safe, synchronized manner.
    I hope this information helps you and is understandable. If you have any questions I will try to clarify. Making things thread-safe can be a daunting task.

  • How to pass submitted Data from a servlet to EJB Session Bean in JPA

    How to pass Data User submitted Data from a servlet to EJB Session Bean when using JPA :
    Hi ,
    I have a jsp page in which the user fills up the Data and submits it to the servlet :
    Inside servlets i am getting all the parameters and setting it to the Entity Class .
    Sample Entity class is shown below :
    @Entity
    public class Employee {
    @Id private int id;
    private String name;
    public Employee() {}
    public Employee(int id) { this.id = id; }
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    }After calling setters of my Entity Class .
    I am using JNDI lookup to call my session Bean method and pass this Entity class to the session Bean to persist data
    Please let me know what will be the right approach :
    1. Passing parameters whole as a Entity Class
    that is
    public void insertData(Employee emp)
    }Or
    2. public void insertData(String Name , int ID)
    }

    they are both right as they both work. Easy huh?
    You might argue that if you have to set a lot of fields, use the entity as otherwise you get a method with a gigantic amount of parameters.

  • Loosing session data between servlets...

    Based on the code below I'm loosing the session data i.e the class indexed by the session id is returning NULL. If anyone has any suggestions I would apprciate it.
    Class 1:
    HttpSession session = request.getSession(true);
    Hashtable books = (Hashtable) session.getValue("books");
    if (books == null)
    books = new Hashtable();
    else
         books = null;
         books = new Hashtable();
    session.putValue("books", books);
    Class 2:
    HttpSession session = request.getSession(true);
    Hashtable booksOrdered = (Hashtable) session.getValue("books");
    System.out.println("booksOrdered: "+ booksOrdered):
    The system.out.println statement returns
    booksOrdered: NULL
    Help please
    Lee Paulison Jr

    I forgot to mention that the code was working up until I installed the March 4 - 28 2002 Windows NT Critical updates. The code worked after the update when I changed to a different login name namely Admin. Then after a few hours it stopped working, and continues not to work on any Login. I hope that this last bit of information helps someone come up with a fix.
    Lee Paulison

  • HT4859 If I got a new iPhone and backed up the data from the old one, it should show up once the new one is set up right? Does an "incomplete" status mean it did not back up and can not be restored to the new iPhone?

    If I got a new iPhone and backed up the date from the old one, it should show up once the new one is set up right?
    And does an "incomplete" status on iCloud mean it can't be restored to the new iPhone?
    Help please

    What I mean is still track my stolen one. I don't know if this will make sense to you but I'm thinking that if I restore the back up data on this phone..on my stolen phone it will like forget the icloud account or something and think this phone is the stolen one so when I go to track the stolen one, it will show that phone as the one I have now because I restored the back up from that phone.

  • Time of email shows in Date Column, Date is not showing on new emails

    Date is not showing in Date column. Only time is showing.
    I just migrated from OE - Old emails show the time & Date.

    If these are emails received today that is normal. Thunderbird assumes you know what day it is and only displays the time for messages received today. It will append the date to these messages at midnight tonight.

  • How do I access session data through an EJB?

    Hi
    How do I access session data through an EJB?
    I am currantly developing a Web service (using ejb's, JBoss.net and Apache Axis). A client making a call to this Web service, is expecting a bussiness-object in return. My problem is that this bussiness-object i stored in a users session data. How do I retrieve this bussiness-object from the users session.
    I have read that this does not work with httpsessions, is this true? If this is true, is it possible to store the bussiness object in a JavaBean e.g:
    <jsp:useBean id="userContextWebImpl" scope="session" class="com.ac.march.client.UserContextWebImpl">
    <%
    String key = "test";
    String value = "This is the value";
    userContextWebImpl.setValue( key, value1 );
    %>
    </jsp:useBean>
    and then retrieve this information through the EJB? Or is it possible to do this by using Statfull JavaBeans? Or can this be done through a nother solution?
    Please help!

    I have created a JavaBean with scope="application" to store some data. The data is stored when a user prefomes a spesific task.
    A different person then makes a call to a Web-Service on the server. The Web-Service then asks an EJB to retrieve the data stored in the JavaBean (servlet cotext). In other words: How do I retrieve this data from the EJB?
    I have tried with this code, but with no luck.
    (ApplicationContextWebImpl is the JavaBean)
    public static String getBookingResult( String key )
         String myResult = null;
         String myKey = key;
         ApplicationContextWebImpl applicationContextWebImpl = null;
         try
              applicationContextWebImpl = new ApplicationContextWebImpl();
              myResult = (String)applicationContextWebImpl.getValue( key );
         catch ( java.rmi.RemoteException e )
         return myResult;
    }

  • Report shows no data in the Viewer

    Hello,
    i'm new to Crystal Reports and i have to develop a few Reports.
    I load the data with a stored procedure form a sql-server. This is working and i get all datas i need. But the Report Viewer doesn't show any data.
    I don't know why.
    If i do it over a select statement and not a stored procedure, the Report Viewer shows me each data set up to 9 times.
    I'm working with three tables.
    Here is the c# code i wrote.
    command = new SqlCommand();
    command.Connection = connection;
    command.CommandType = CommandType.StoredProcedure;
    SqlParameter myParam = new SqlParameter("@FormulareAuftragNr", SqlDbType.VarChar, 5);
    myParam.Value = AuftragNr;
    command.Parameters.Add(myParam);
    command.CommandText = "dbo.Abfrage_Arbeitsplan_Bericht";
    connection.Open();
    SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
    ds = new DataSet("ABC");
    dataAdapter.Fill(ds, "dbo.Abfrage_Arbeitsplan_Bericht");
    druckarbeitsplan.SetDataSource(ds);
    CR Version : latest
    VS Version : 10.30319.1
    OS : Windows 7
    it is for an Windows App
    Johannes

    CR Version : latest
    That is not enough info. All my content below is based on the assumption that you are using CRVS2010 (V. 13.x)...
    The code does not show you loading an actual report(?). Also, I'm assuming that after:
    druckarbeitsplan.SetDataSource(ds);
    you have code to show the report in the viewer or you're printing  exporting the report?
    For datasets see [this|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333533323335333433333332%7D.do] KB. Also, make sure you are using the full 4.0 framework, not the client framework.
    Ludek
    Follow us on Twitter http://twitter.com/SAPCRNetSup
    Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

  • Could not deserialize session data, java.io.InvalidClassException

    Whenever I click on logout link from Liferay(Which deployed as application on Weblogic 10.3),It shows below Exception in the console however i am able to logout sucessfully.
    Could not deserialize session data.
    java.io.InvalidClassException: org.hibernate.proxy.pojo.javassist.SerializableProxy; local class incompatible: stream classdesc serialVersionUID = 1180036893511205383, local class serialVersionUID = -2265249369383210104 at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:560)
    It seems to be Classpath polluted with different hibernate jars.But still not able to figure it out.Below is the jar files which i have in classpath.
    hibernate-annotations.jar
    hibernate-commons-annotations.jar
    hibernate-core.jar
    hibernate3.jar
    Application Server: Weblogic 10.3
    Any Help would be much appreciated.

    Sounds like you have two different versions of a class in the two applications.
              If you change a class implementation and recompile - the updated class gets a new UID. Looks like maybe one app has a jar with the older class and the other app has a jar with the new class.

Maybe you are looking for