Servlet sessions

As per theory an HttpSession is needed only in case the following three conditions are met
1. Your application entails multiple http requests.
2. You need to remember certain data between requests.
3. There is a server side object that needs to persist between requests.
OK now I am having difficulty in fully understanding and applying what this exactly implies. Consider a use case a client logs into a service through a trusted portal i.e., the portal authenticates the user creates a hash and sends over the login and the hash over to an application using a servlet. The servlet(application) authenticates the portal using the hash and lets the user log in to perform various functions. Now in this scenario lets suppose the request to the application for authentication consists of LoginID and Hash
http://myApplication.eu.com/servlet/Login?LoginID=amit234&Hash=123465432355765432344566788766544
now here do we need to store the LoginID and the Hash in a session or not and why?
Thanx for replying.

An HttpSession is not necessarily needed in the three
conditions you list.
1. Doesn't matter...you may not need to maintain
state.
2. You need to maintain state. You can embed a token
in the page
url, or cookie and retrieve the information from a
m a data store.
3. You can persist an object independant from an
HttpSession.
In your use case study:
You do not need to use an HttpSession. After
authentication you can embed a unique token in the
page, url, or client cookie. Which will need to be
checked each time your client access a safe page.
Of course using a HttpSession is convenient.
You would need more than a LoginID each time if you do
not use a session. If you are using a session then you
do not need either, as the session takes care of that
for you.
Hi,
But am i wrong in saying that the a servlet is instantiated only when its first loaded not with each request. If thats the case, how are u going to differentiate between same attributes of different requests. Is it that the servlets use different threads for the purpose which are distinct and unique for each request or do they employ some other method to achieve this?

Similar Messages

  • Weblogic 8.1 SP2 + Struts + Internal Servlet Session Process Error Found!

    Hi,
              I have developed a struts 1.1 based webapplication which runs fine on
              weblogic 7 (for one year in production), tomcat 4.1,5 and others but
              refuses to function in weblogic 8.1 sp2!
              This is the stacktrace I get when I try to call an action via the browser:
              java.lang.IllegalStateException: Internal Servlet Session Process Error
              Found!
                   at
                   weblogic.servlet.internal.session.SessionData.checkProcess(SessionData.java:1148)
                   at
                   weblogic.servlet.internal.session.SessionData.setAttribute(SessionData.java:501)
                   at
                   org.apache.struts.action.RequestProcessor.processLocale(RequestProcessor.java:638)
                   at
                   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:230)
                   at
                   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1420)
                   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:502)
                   at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
                   javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
                   weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
                   at
                   weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
                   at
                   weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
                   at
                   weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
                   at
                   weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
                   at
                   weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
                   at
                   weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
                   at
                   weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
                   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197) at
                   weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
              Just out of curiosity I deployed the struts-examples webapplication from
              the apache jakarta struts distribution and it also fails to run with the
              same error!
              Can anybody help me out with this one? Does anybody experience the same
              thing?
              regards,
              oliver
              p.s. I will also post this message on the struts user list.
              

    Hi,
              I have developed a struts 1.1 based webapplication which runs fine on
              weblogic 7 (for one year in production), tomcat 4.1,5 and others but
              refuses to function in weblogic 8.1 sp2!
              This is the stacktrace I get when I try to call an action via the browser:
              java.lang.IllegalStateException: Internal Servlet Session Process Error
              Found!
                   at
                   weblogic.servlet.internal.session.SessionData.checkProcess(SessionData.java:1148)
                   at
                   weblogic.servlet.internal.session.SessionData.setAttribute(SessionData.java:501)
                   at
                   org.apache.struts.action.RequestProcessor.processLocale(RequestProcessor.java:638)
                   at
                   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:230)
                   at
                   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1420)
                   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:502)
                   at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
                   javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
                   weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
                   at
                   weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
                   at
                   weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
                   at
                   weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
                   at
                   weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
                   at
                   weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
                   at
                   weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
                   at
                   weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
                   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197) at
                   weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
              Just out of curiosity I deployed the struts-examples webapplication from
              the apache jakarta struts distribution and it also fails to run with the
              same error!
              Can anybody help me out with this one? Does anybody experience the same
              thing?
              regards,
              oliver
              p.s. I will also post this message on the struts user list.
              

  • Servlet Session Object

              I need to get the lastAccessTime of the servlet which I have deployed on Weblogic
              7.0.
              I have found that by using ServletSessionRuntimeMBean interface which has a method
              called getTimeLastAccessed, I can get the same.
              I am not able to get the same. Can any one sujject the way I have to go for this.
              

    Hello Linus,
    Actually, you would want to retrieve the necessary objects from your servlet context
    and then pass them along to your session EJBs. It's not necessary to pass the
    entire ServletContext object to your session bean. You should wrap the values
    in DTOs (Data Transfer Objects / Value Objects) and pass them along to your session
    beans. Also, it's not good to couple your EJBs with Servlets, as they may be eventually
    accessed from standalone clients in the future. For more information on this design
    pattern, please see the following link:
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669
    "Linus Nikander" <[email protected]> wrote:
    Is it possible to accesss objects stored in a Servlet session context
    from
    an EJB ? If so, how ?
    //Linus Nikander - [email protected]

  • IllegalStateException: Internal Servlet Session Process Error Found!

              I keep getting the annoying error as listed, and the server also keeps reporting
              that I can only connect from 0 unique ip addresses. Has anybody else seen these
              type of frustrations on 8.1 sp2, or can explain them.
              With as much detail omitted for simplicity;
              Frustration 1.
              I have a 8sp2 server running all ok, occasionally after a redeploy of an ear file
              I attempt to load a jsp file, and the error below is thrown.
              The JSP has a bean which is session based, and as from following the stack trace
              it is around some weblogic code which tests if my license allows access to the
              http session (on a developer license). I then have to start another server instance
              and do a deployment of a v.simple war, and access this, then deploy the same war
              to the broken server and access that, then the initial jsp works fine. no code
              changes just environment stops, starts and redeploys!
              Frustration 2
              Server runs ok, tray and connect from two machines (I have an ldap server that
              wants to 'broadcast' messages to my server), error of too many connections.
              The ip connection issues can in most cases be removed with a server restart.
              EXCEPTION TRACE
              java.lang.IllegalStateException: Internal Servlet Session Process Error Found!
              With the following stack trace:
              java.lang.IllegalStateException: Internal Servlet Session Process Error Found!
                   at weblogic.servlet.internal.session.SessionData.checkProcess(SessionData.java:1148)
                   at weblogic.servlet.internal.session.SessionData.setAttribute(SessionData.java:501)
                   at jsp_servlet._security.__changeprofile._jspService(__changeprofile.java:135)
                   at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
                   at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:446)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
                   at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
                   at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
                   at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
                   at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
                   at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
                   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
                   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
              

              I have the same problem. Could any one help us?
              "David" <[email protected]> wrote:
              >
              >I keep getting the annoying error as listed, and the server also keeps
              >reporting
              >that I can only connect from 0 unique ip addresses. Has anybody else
              >seen these
              >type of frustrations on 8.1 sp2, or can explain them.
              >
              >With as much detail omitted for simplicity;
              >
              >Frustration 1.
              >I have a 8sp2 server running all ok, occasionally after a redeploy of
              >an ear file
              >I attempt to load a jsp file, and the error below is thrown.
              >
              >The JSP has a bean which is session based, and as from following the
              >stack trace
              >it is around some weblogic code which tests if my license allows access
              >to the
              >http session (on a developer license). I then have to start another
              >server instance
              >and do a deployment of a v.simple war, and access this, then deploy the
              >same war
              >to the broken server and access that, then the initial jsp works fine.
              > no code
              >changes just environment stops, starts and redeploys!
              >
              >Frustration 2
              >Server runs ok, tray and connect from two machines (I have an ldap server
              >that
              >wants to 'broadcast' messages to my server), error of too many connections.
              >The ip connection issues can in most cases be removed with a server restart.
              >
              >
              >EXCEPTION TRACE
              >
              >java.lang.IllegalStateException: Internal Servlet Session Process Error
              >Found!
              >
              >With the following stack trace:
              >
              >java.lang.IllegalStateException: Internal Servlet Session Process Error
              >Found!
              >     at weblogic.servlet.internal.session.SessionData.checkProcess(SessionData.java:1148)
              >     at weblogic.servlet.internal.session.SessionData.setAttribute(SessionData.java:501)
              >     at jsp_servlet._security.__changeprofile._jspService(__changeprofile.java:135)
              >     at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
              >     at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
              >     at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
              >     at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:446)
              >     at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
              >     at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
              >     at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
              >     at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
              >     at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
              >     at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
              >     at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
              >     at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
              >
              >
              

  • Servlet Sessions+dont have a clue

    im trying to get a servlet session goin for a college project,i know its hard to help someone on this but please try this is driving me mad,,,
    im useless at java so i have just being piecing together other peoples code and trying to get it working,
    Iam trying to accept a username and password for the Oracle database and then put the resulting database connection into a session variable...
    here is my useless code,,,please help....the only error iam getting is to do with the PrintWriter,,,
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    // You need to import the java.sql package to use JDBC
    import java.sql.*;
    public class LoginServlet1 extends HttpServlet
    private Connection con=null;
    public LoginServlet1(Connection con){
    this.con=con;
    public Connection getConnection(){
    return con;
    public void doGet(HttpServletRequest request,HttpServletResponse response)
              PrintWriter writer = response.getWriter();
              HttpSession session = request.getSession(true);
              String username = null;
              String password = null;
              String strHTML = "";
              boolean success = false;
                   if (((username==null) || (username.compareTo("")==0)))
                        strHTML = strHTML + "<title> Lab #11 Login Error </title>";
                        strHTML = strHTML + "</head>";
                        strHTML = strHTML + "<body bgcolor=white>";
                        strHTML = strHTML + "Massive Error --- you need to provide a username ...please try again ...<BR><BR>";
                        strHTML = strHTML + "Back to the login page ..<A HREF=\"../login.html\"> click here </A>";
                        strHTML = strHTML + "</body>";
                        strHTML = strHTML + "</html>";
                        success = false;
                   else if (((password==null) || (password.compareTo("")==0)))
                        strHTML = strHTML + "<title> Lab #11 Login Error </title>";
                        strHTML = strHTML + "</head>";
                        strHTML = strHTML + "<body bgcolor=white>";
                        strHTML = strHTML + "Massive Error --- you need to provide a password ... please try again ...<BR><BR>";
                        strHTML = strHTML + "Back to the login page ...<A HREF=\"../login.html\"> click here </A>";
                        strHTML = strHTML + "</body>";
                        strHTML = strHTML + "</html>";
                        success = false;
                   else
                   try
                             // Load Oracle driver
                             DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                             LoginServlet1 holder=(LoginServlet1) session.getValue("servletapp.connection");
                             if(holder==null){
                             try{
                             holder= new LoginServlet1(DriverManager.getConnection("jdbc:oracle:thin:@macha.wit.ie:1521:MACH"));
                             session.putValue("servletapp.connection",holder);
                             catch(SQLException e){
                             getServletContext().log(e, "No");
                             success= true;
                        catch (SQLException sqlex)
                             strHTML = strHTML + "connection failed ....<BR>";
                             if (sqlex.getErrorCode()==1017)
                                  strHTML = strHTML + "OUPS !!! wrong username or password lads ...please try again ...<BR><BR>";
                             else
                                  strHTML = strHTML + "SQL Error happened ....<BR>";
                                  strHTML = strHTML + "Error Number = " sqlex.getErrorCode() "<BR>";
                                  strHTML = strHTML + "Error Message = " + sqlex.getMessage() + "<BR>";
                                  strHTML = strHTML + "ah common cheer up, it's not the end of the world...<BR>";
                             strHTML = strHTML + "Back to the login page<A HREF=\"../login.html\"> click here </A>";
                             success = false;
                        if (success)
                             try
                             getServletConfig().getServletContext().getRequestDispatcher("/WEB-INF/jsp/query.jsp").forward(request,response);
                             catch (Exception ex) {
              ex.printStackTrace ();

    back again,,
    the code above is causing the following error when i try to run it,,
    Apache Tomcat/4.0.4 - HTTP Status 500 - Internal Server Error
    type Exception report
    message Internal Server Error
    description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
    the error goes on to give a very long list of exceptions and root causes,there is nothing wrong with Tomcat because i can run the other version of this program that doesnt have any sessions is it,,,
    thanks

  • How to share objects between two ADF Faces servlet sessions

    I gather the application scope is one way to go for sharing data between sessions in an ADF application. Are there other more generic methods of sharing data between servlet sessions?
    For example, let's say we have a JDev 101.3 ADFBC/JSF app. (or JDev 11g for that matter). In this app we also register a servlet in web.xml. So two people log into this application and access this defined servlet, creating two instances of that servlet...I guess. Is there a way for those two instances/sessions to talk to each other? Pass data back and forth? Should I read about JMS? Or does application scope sound better? I guess a direct communication would be more tidy, than putting data on an application bulletin board, lilke application scope.
    Any thoughts?

    Hi,
    Only one instance of each servlet defined in web.xml gets created, not one per user. You're right about the sessions though, one per user is created. You're right on the other parts as well I think you could use application scope to do something like that, or the data base for that matter, depending on the use case.
    Regards,
    ~ Simon

  • Servlet Session Monitoring via MBeans turns up no MBeans

    Hi,
    I discovered more about why I'm not seeing any Servlet Session Runtime
    MBeans when I enable session monitoring. It looks like each time my
    managed server creates a new session, two errors get written to my
    WebLogic log:
    "####<Sep 22, 2002 6:46:43 PM EDT> <Warning> <Dispatcher>
    <chile.iso-ne.com> <adminserver> <ExecuteThread: '7' for queue:
    '__weblogic_admin_rmi_queue'> <> <> <000000> <RuntimeException thrown
    by rmi server: 'weblogic.rmi.internal.BasicServerRef@10b - jvmid:
    '7074298665992588400S:10.145.220.82:[7001,7001,7002,7002,7001,7002,-1]:smsdomain:adminserver',
    oid: '267', implementation:
    'weblogic.management.internal.AdminMBeanHomeImpl@3c7b65''>
    weblogic.management.NoAccessRuntimeException: User guest does not have
    access permission on weblogic.admin.mbean.MBeanHome
    at weblogic.management.internal.Helper.checkAdminPermission(Helper.java:1637)
    and
    "####<Sep 22, 2002 6:46:43 PM EDT> <Error> <HTTP Session>
    <chile.iso-ne.com> <webuiserver> <ExecuteThread: '0' for queue:
    'default'> <> <> <100032> <Error creating servlet session runtime>
    weblogic.management.NoAccessRuntimeException: User guest does not have
    access permission on weblogic.admin.mbean.MBeanHome
    at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:85)
    at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:136)
    at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)
    at $Proxy7.getMBeanServer(Unknown Source)
    at weblogic.management.internal.MBeanHomeImpl.isAdminHome(MBeanHomeImpl.java:93)
    at weblogic.management.internal.MBeanHomeImpl.getMBean(MBeanHomeImpl.java:118)
    at weblogic.management.internal.MBeanHomeImpl.getRuntimeMBean(MBeanHomeImpl.java:590)
    at weblogic.management.internal.MBeanHomeImpl.getRuntimeMBean(MBeanHomeImpl.java:568)
    at weblogic.servlet.internal.session.SessionData$1.run(SessionData.java:185)
    at weblogic.management.internal.Helper.doLocally(Helper.java:1656)
    at weblogic.servlet.internal.session.SessionData.getRuntimeMBean(SessionData.java:179)
    at weblogic.servlet.internal.session.SessionData.<init>(SessionData.java:166)
    Looks like the managed server is making a request of the admin server
    and propagating the "guest" principal instead of "system".
    These principal propagation errors from managed-to-admin seem to
    happen all over the place with different MBeans, and get patched one
    place at a time in various BEA service packs. For instance, there's
    another issue with accessing the XML Entity Cache from a managed
    server, and I'm sure I've read about others. Isn't there a way to
    make sure these errors no longer occur with any MBean requests from
    the managed server?
    Jim

    Add
    acl.access.weblogic.admin.mbean.MBeanHome=guest
    in the filerealm.properties file.
    Jim Doyle wrote:
    Hi,
    I discovered more about why I'm not seeing any Servlet Session Runtime
    MBeans when I enable session monitoring. It looks like each time my
    managed server creates a new session, two errors get written to my
    WebLogic log:
    "####<Sep 22, 2002 6:46:43 PM EDT> <Warning> <Dispatcher>
    <chile.iso-ne.com> <adminserver> <ExecuteThread: '7' for queue:
    '__weblogic_admin_rmi_queue'> <> <> <000000> <RuntimeException thrown
    by rmi server: 'weblogic.rmi.internal.BasicServerRef@10b - jvmid:
    '7074298665992588400S:10.145.220.82:[7001,7001,7002,7002,7001,7002,-1]:smsdomain:adminserver',
    oid: '267', implementation:
    'weblogic.management.internal.AdminMBeanHomeImpl@3c7b65''>
    weblogic.management.NoAccessRuntimeException: User guest does not have
    access permission on weblogic.admin.mbean.MBeanHome
    at weblogic.management.internal.Helper.checkAdminPermission(Helper.java:1637)
    and
    "####<Sep 22, 2002 6:46:43 PM EDT> <Error> <HTTP Session>
    <chile.iso-ne.com> <webuiserver> <ExecuteThread: '0' for queue:
    'default'> <> <> <100032> <Error creating servlet session runtime>
    weblogic.management.NoAccessRuntimeException: User guest does not have
    access permission on weblogic.admin.mbean.MBeanHome
    at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:85)
    at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:136)
    at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)
    at $Proxy7.getMBeanServer(Unknown Source)
    at weblogic.management.internal.MBeanHomeImpl.isAdminHome(MBeanHomeImpl.java:93)
    at weblogic.management.internal.MBeanHomeImpl.getMBean(MBeanHomeImpl.java:118)
    at weblogic.management.internal.MBeanHomeImpl.getRuntimeMBean(MBeanHomeImpl.java:590)
    at weblogic.management.internal.MBeanHomeImpl.getRuntimeMBean(MBeanHomeImpl.java:568)
    at weblogic.servlet.internal.session.SessionData$1.run(SessionData.java:185)
    at weblogic.management.internal.Helper.doLocally(Helper.java:1656)
    at weblogic.servlet.internal.session.SessionData.getRuntimeMBean(SessionData.java:179)
    at weblogic.servlet.internal.session.SessionData.<init>(SessionData.java:166)
    Looks like the managed server is making a request of the admin server
    and propagating the "guest" principal instead of "system".
    These principal propagation errors from managed-to-admin seem to
    happen all over the place with different MBeans, and get patched one
    place at a time in various BEA service packs. For instance, there's
    another issue with accessing the XML Entity Cache from a managed
    server, and I'm sure I've read about others. Isn't there a way to
    make sure these errors no longer occur with any MBean requests from
    the managed server?
    Jim--
    Rajesh Mirchandani
    Developer Relations Engineer
    BEA Support

  • Get the Web users Clipboard text in Servlet session

    We have a small web application � uses JSPs , Servlets and runs on Tomcat Server.
    We are trying to get the end web user�s ( browsers ) Clipboards copied text in our Servlets session.
    We know there is some AWT API to get the Clipboards copied data.
    java.awt.datatransfer.Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    // Get data from clipboard
    java.awt.datatransfer.Transferable clipData = clipboard.getContents(clipboard);
    But if we use this piece of code in our servlet session, we always get the Clipboard text, which is copied on the Server. Not at the users / browsers.
    So, we wonder are there any ways or similar to get the Users clipboard text in that users session.
    Any help would be great.

    Its the same old story.
    Java code is only running on the server.
    At the client end all you can work with is HTML and javascript.
    With Internet explorer you can access clipboard data:
    http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/clipboarddata.asp?frame=true
    Grab it with javascript, put it into a hidden field, and submit the page.
    That will pass it as a request parameter to your jsp/servlet, and you can get at it that way.

  • Servlet session problem

    hi all,
    I am new to servlet. i have creted a server program and many user can login using thier username ,role and password. if more than one user can login simultaneously i could nt able to mainatin the session, it always showing the last login datas to all users(who'slogin earlier). how do i solve this and please any one explain me with some example?
    regards
    sm

    if more than one user can login simultaneously i could nt able to mainatin the session, it always showing the last login datas to all users(who'slogin earlier). Do you mean to say different users logging into the system using same browser window?
    how do i solve thisThis is more about what do you want to do? One solution might be :- if the user authentication succeeds, add a logic that will invalidate the previous session and create a new session for this new user.

  • Passing objects to a servlet - session or as byte[]

    Hi
    I'm creating my first servlet and I want opinions on my design. I plan to sue my servlet to generate an image. So in my jsp page I have an image tag with the following
    <img src="/Servlet/GenerateImage">But my servlet requires data in an ArrayList from my JSP page. How can I pass the ArrayList to my servlet? I've done some research and been looking aorund the forums, and I noticed people either convert the object to byte[] or pass the object using the session. I've tried doing the byte[] method but I don't know how to pass the byte[] to my servlet. I tried passing it as a parameter using a query string, get the parameter as a string, and convert it to byte[] again, but it didn't work. I can't seem to get this approach to work.
    I'm worried that if I use the session, and a large number of people access my page which runs the servlet, my server will be bogged down.
    What is the best approach in doing this? It'd be great if some sample code or links are supplied
    Thanks for all the help!

    My servlet requires data in an ArrayList from my
    JSP page. How can I pass the ArrayList to my servlet?
    I've done some research and been looking aorund the
    forums, and I noticed people either convert the object
    to byte[] or pass the object using the session. If the ArrayList is derived in the JSP and is required in the servlet, then saving it as a session attribute is the best bet. I guess it would be possible to send all the data from the ArrayList to the client in a cookie, but that seems messy and inefficient.
    I'm worried that if I use the session, and a large
    number of people access my page which runs the
    servlet, my server will be bogged down.The session attribute only contains a reference to the ArrayList and so in itself does not cause a performance problem. If you're concerned that the ArrayList is very large, you could consider saving the info to a disk file. Alternatively, could the ArrayList be derived in the servlet instead of, or as well as, the JSP? Does the servlet need all the Arraylist entries, or just a subset? If a subset, save that as a session attribute and dereference the ArrayList in the JSP. Also, think about when the ArrayList reference can safely be removed from the session.
    What is the best approach in doing this? It'd be great
    if some sample code or links are suppliedJSP
    <jsp:useBean id="myArrayList" class="java.util.ArrayList" scope="session"/>Servlet
    HttpSession session = request.getSession();
    ArrayList al = (ArrayList) session.getAttribute("myArrayList");
    .

  • Servlet session managment

    Hi
    I am trying to set object in session
    first I set object in session in first servlet as session.setAttribute("name"object);
    this session obj can retrive in jsp page
    I make one link <a href="abc which call another servlet
    I want this session object can retrive in that servlet but this get null
    How yo solve this problem

    Are both the servlets in the same web app?
    Your session cannot be accessed across multiple webapps

  • 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.

  • Servlet session performance.

    I am currently in the processes of changing a web interface from using and
              applet on the client side to doing servlet transactions on the server side.
              I was wanting to store alot of info in the users HttpSession in XML format
              and then use a DOM to read it back in. Does any one know what kinda of
              performance issues i can expect from the session?(if any)
              Thanks.
              

    Casey Miller wrote:
              >
              > I am currently in the processes of changing a web
              > interface from using and applet on the client side to
              > doing servlet transactions on the server side.
              > I was wanting to store alot of info in the users
              > HttpSession in XML format and then use a DOM to read
              > it back in. Does any one know what kinda of
              > performance issues i can expect from the session?(if any)
              Sessions will store any old object. Is there a reason you are making
              life harder for yourself and not storing a parsed DOM? Or even
              specialized data structures? The only gotcha that comes to mind is to
              make sure your data objects implement Serializable if you are clustering
              or persisting sessions (and not a bad idea to do in general).
              Jeff
              

  • Servlet session persistance within iAS 6.0 SP3

    Hi,
    Is it possible to provide failover for servlets, keeping session
    persistance, between 2 iAS in a cluster?
    What I trying to do is to use the iAS to provide me redundancy for an
    application that is 100% based on Servlets and JSP (no EJBs). Is this
    possible?
    Marcelo Manta
    Barcelona Technology Center
    [email protected]
    phone: +34 67 699-5921 (ESN 746)

    Hi Manta,
    Yes, it is very well possible with iAS.
    If your application is already deployed than to make that distributed so
    that both the iAS(Primary and Backup) will store the sesson information,
    you need to change few entries of your application in the registry of
    both iAS, these are -
    - run kregedit
    - go to iplanet/Application Server/6.0/J2EE-Module/<App_name> node
    than
    - insert your domain name value in session-domain key.
    - modify the session-impl key value to distributed.
    - insert the session-path key value as / (slash)
    - ensure that the key session-dsync-type is dsync-distributed
    at the end, your key values should look like this -
    - session-domain=your.domain.name
    - session-dsync-type=dsync-distributed
    - session-impl=distributed
    - session-path=/
    Note: you should make these changes in the registry of all the iAS
    servers that are participating in your cluster, or you can redeloy the
    Application on all the servers, with appripriate deployment descriptor.
    Than restart the two web servers(iws) and the two iAS servers in the
    cluster.
    Note: start the highest priority server(Primary) first.
    The clustering and the distributed session failover can be better seen
    through the clustering-examples/samples provided with iAS, like
    clustering-servlet and clustering-jsp.
    Please see the page:
    http://<hostname.domainname>:<http-port>/ias-samples
    for all the sample applications that comes with iAS and
    http://<hostname.domainname>:<http-port>/ias-samples/cluster/docs/index.html
    for cluster related sample application.
    Please feel free to mail me if you have any further queries.
    Sanjeev,
    Developer Support Group iAS
    "Manta, Marcelo [BLMES:0B70:EXCH]" wrote:
    Hi,
    Is it possible to provide failover for servlets, keeping session
    persistance, between 2 iAS in a cluster?
    What I trying to do is to use the iAS to provide me redundancy for an
    application that is 100% based on Servlets and JSP (no EJBs). Is this
    possible?
    Marcelo Manta
    Barcelona Technology Center
    [email protected]
    phone: +34 67 699-5921 (ESN 746)

  • Servlet session tracking without encodeUrl()

    Hi,
    I'd like use sessions without classic tracking where references are completely encoded by encodeUrl(). I thought about something like "servlet?sessionId=xxx&otherparam=yyyy". Can I do it with compatibility with classic session objects?
    Thanks in advance,
    Tom

    Hi,
    I'd like use sessions without classic tracking where references are completely encoded by encodeUrl(). I thought about something like "servlet?sessionId=xxx&otherparam=yyyy". Can I do it with compatibility with classic session objects?
    Thanks in advance,
    Tom

Maybe you are looking for