How to remove session scope?

Hi,
I instantiated a bean using the JSP useBean tag and set its session scope to session. I want to at one point be able to remove the bean from session, how can I do this?
regards
Siliconbt

you make the bean object null then u can remove the session.
the above answer given in my view
if any pls forward to me

Similar Messages

  • How to use Session scope in jsp page

    Hello, I have login form, where user provides username and password. Then click on submit, it will forward to validation.jsp. Where it will check in database make sure username and password exit. Now i can also retrive accountid of perticular user. I want to put that username and accountid in session scope. so all other pages can use that username and accountid. How can i do that. I'm new at this, so please provide me example too. Here is my code for login.jsp and validation.jsp..
    Validation.jsp
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    //String name = request.getParameter( "username" );//
    //session.setAttribute( "accountID",accountID );//
    <%
    String connURL = "jdbc:oracle:thin:@orca.csc.ncsu.edu:1521:ORCL";
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    conn = DriverManager.getConnection(connURL, "vapatel","pjdas");
    stmt = conn.createStatement();
    String user=request.getParameter("userName");
    String password=request.getParameter("password");
    boolean entrance=false;
    stmt.excuteQuery("SELECT AccountID From Password WHERE USERNAME='"+user+"'");
    rs = stmt.executeQuery("SELECT * FROM Password WHERE USERNAME='"+user+"' AND PASSWORD='"+password+"'");
    while(rs.next()){
    String dbUser = rs.getString("USERNAME");
    String dbPassword= rs.getString("PASSWORD");
    if ((user.equals(dbUser)) && (password.equals(dbPassword))){
    entrance=true;
    if (entrance==true){%>
    <jsp:forward page="form.jsp"/>
    <%}
    else{%>
    <jsp:forward page="login.jsp"/>
    <%}
    %>

    hi,
    to put something into session scope in a jsp page use:
    session.setAttribute("counter", Integer.toString(5));to retrieve is from a jsp page use:
    String counterAttribute = (String)session.getAttribute("counter");

  • How to setup session scope in servlet?

    bean tag can be used in jsp to setup its scop, like
    <jsp:usebean id="abc" class="def" scope="session"/>
    but is it possible to setup session scope to divide two users in order not to use the same bean? becuase i encounter a problem that, when using bean in servlet, seemly A user would access the data that B user just store in; at first, i try to compare if session == null or session.isNew(), but finally find out that their session.getId() is difference, thus i suppose that if i am able to decide via users' session id to limit their access to the bean just as jsp:usebean does!
    is that right? or in what way is better?(i am now to rewrite my original code, it's a little bit complicate for some reasons, so i think, if possible, that via compare session id, that i do not know how, would be a better way!)
    thanks in advice,

    If each user has a separate session, then each one
    should get their own instance of the bean. Is it
    possible that that you store and retrieve a reference
    to the bean in a servlet instance variable? That
    would cause the problem you describe.do you mean by putting variable in situation like A) ; yes i did, but if i put bean in the body of doPost method, each time when bean are "new"ed, there may be error occurred, accounting for i hope to instantize with default value, but default constructor do nothing; thus if by only construct with default constructor, error would occurred and so a new constructor with parameters i put in the position you refferred to! would you like to tell me what's the right way for i am not so familiar with servlet.
    thanks in advice,
    A)
    public class MyClassName extends HttpServlet {
    BeanClass myBean = new BeanClass();
    ... doGet(...){}
    ... doPost(...){...}

  • How can a session scope bean access an application scope bean - help

    Hello,
    I have a JSP page that has references to an Application Scope and a Session Scope bean...
    <jsp:useBean id="myWebApp" scope="application" class="com.my.web.WebApplication" />
    <jsp:useBean id="myWebSession" scope="session" class="com.my.web.WebSession" />
    I would like the WebSession access methods in the WebApplication ... Can/ How does the WebSession object lookup the reference to WebApplication object?

    I don't think you should make the WebSession implement the session listener.
    The session listener will be created once, at the start of the servlet context and would be listening to all sessions. So you would have one instance of the WebSession belonging to the context (though not as an attribute), and others belonging to each session. This will be confusing in your code, I think.
    I would suggest having a different class act as the HttpSessionListener. Perhaps do something like this:
    public class WebSessionInjector implements HttpSessionListener {
      public void  sessionCreated(HttpSessionEvent e) {
        WebApplication webApp = (WebApplication)(e.getSession().getServletContext().getAttribute("webapp"));
        WebSession mySession = new WebSession();
        mySession.setWebApplication(webApp);
        e.getSession().setAttribute("mySession", mySession);
      public void sessionDestroyed(HttpSessionEvent e) { ... }
    }You may be able to use the WebApplication object itself as the listener ...
    Or, you could make the WebSession implement the HttpSessionBindingListener and use the valueBound event much like the sessionCreated event above, but from inside the WebSession object:
    public class WebSession implements HttpSessionBindingListener {
      public void  valueBound(HttpSessionBindingEvent e) {
        WebApplication webApp = (WebApplication)(e.getSession().getServletContext().getAttribute("webapp"));
        this.setWebApplication(webApp);
      public void valueUnbound(HttpSessionBindingEvent e) { ... }
    }

  • How to remove session by database name

    Hi , 
    using exec sp_who will show the list of all the sessions.
    How i can remove all the session listed by sp_who by database name like master , etc
    Thank You , Shan Ali Khan

    This is a simple sp_who I named sp_who3  extrapolated by a 2008R2 instance, but you need to make your own and put to master.
    alter procedure sp_who3 (--- 1995/11/28 15:48
    @dbname varchar(max) = null ,
    @loginame sysname = NULL --or 'active'
    as
    declare @spidlow int,
    @spidhigh int,
    @spid int,
    @sid varbinary(85)
    select @spidlow = 0
    ,@spidhigh = 32767
    if ( @loginame is not NULL
    AND upper(@loginame collate Latin1_General_CI_AS) = 'ACTIVE'
    begin
    select spid , ecid, status
    ,loginame=rtrim(loginame)
    ,hostname ,blk=convert(char(5),blocked)
    ,dbname = case
    when dbid = 0 then null
    when dbid <> 0 then db_name(dbid)
    end
    ,cmd
    ,request_id
    from sys.sysprocesses
    where spid >= @spidlow and spid <= @spidhigh AND
    upper(cmd) <> 'AWAITING COMMAND'
    and ((case
    when dbid = 0 then null
    when dbid <> 0 then db_name(dbid)
    end = @dbname) or (@dbname is null))
    return (0)
    end
    if (@loginame is not NULL
    AND upper(@loginame collate Latin1_General_CI_AS) <> 'ACTIVE'
    begin
    if (@loginame like '[0-9]%') -- is a spid.
    begin
    select @spid = convert(int, @loginame)
    select spid, ecid, status,
    loginame=rtrim(loginame),
    hostname,blk = convert(char(5),blocked),
    dbname = case
    when dbid = 0 then null
    when dbid <> 0 then db_name(dbid)
    end
    ,cmd
    ,request_id
    from sys.sysprocesses
    where spid = @spid and
    ((case
    when dbid = 0 then null
    when dbid <> 0 then db_name(dbid)
    end) = @dbname or (@dbname is null))
    end
    else
    begin
    select @sid = suser_sid(@loginame)
    if (@sid is null)
    begin
    raiserror(15007,-1,-1,@loginame)
    return (1)
    end
    select spid, ecid, status,
    loginame=rtrim(loginame),
    hostname ,blk=convert(char(5),blocked),
    dbname = case
    when dbid = 0 then null
    when dbid <> 0 then db_name(dbid)
    end
    ,cmd
    ,request_id
    from sys.sysprocesses
    where sid = @sid and
    (( case
    when dbid = 0 then null
    when dbid <> 0 then db_name(dbid)
    end) = @dbname or (@dbname is null))
    end
    return (0)
    end
    -- loginame arg is null
    select spid,
    ecid,
    status,
    loginame=rtrim(loginame),
    hostname,
    blk=convert(char(5),blocked),
    dbname = case
    when dbid = 0 then null
    when dbid <> 0 then db_name(dbid)
    end
    ,cmd
    ,request_id
    from sys.sysprocesses
    where spid >= @spidlow and spid <= @spidhigh and
    (( case
    when dbid = 0 then null
    when dbid <> 0 then db_name(dbid)
    end) = @dbname or (@dbname is null))
    return (0) -- sp_who

  • How-to remove application scope bean

    I've found the following snippets to get rid of a session bean (to have it removed / recreated):
    snippet 1:
    FacesContext
         .getCurrentInstance()
         .getApplication()
         .createValueBinding( "#{yourBeanName}").setValue(FacesContext.getCurrentInstance(), null );snippet 2:
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("userBean");Would that work for application scoped beans as well? Is there a way of getting a list of all jsf beans? I need to re-initialize the web-application without deployment :S
    thanks,
    david

    Yeah, I've tried it and it's looking good.
    Is there any way I can get a list of (application scoped) jsf beans?

  • Cant able to get the output while using session scope

    Hi
    I am using jdeveloper 11.1.1.5
    As i posted in the previous post i had made some changes still i am not getting proper output
    These are steps that i had followed for developing login page
    1.I had created a TaskFlow in adfc-config.xml such that if the login is success it navigates to the other page pls verfiy the link
    http://www.4shared.com/photo/5PNrf1hd/E028_2.html
    2.I had also changed the scope to session in adfc-config.xml
    http://www.4shared.com/photo/HtVVOw_B/E029.html
    3.This was my Welcome.jspx code
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
      <jsp:directive.page contentType="text/html;charset=UTF-8"/>
      <f:view>
        <af:document id="d1" binding="#{sessionScope.backing_welcome.d1}">
          <af:form id="f1" binding="#{sessionScope.backing_welcome.f1}">
            <af:inputText label="UserName" binding="#{backing_welcome.it1}"
                          id="it1" value="#{sessionScope.backing_welcome.auser}"/>
            <af:inputText label="Password" binding="#{backing_welcome.it2}"
                          id="it2"
                          value="#{sessionScope.backing_welcome.apassword}"/>
            <af:commandButton text="Login"
                              binding="#{backing_welcome.cb1}" id="cb1"
                              action="#{backing_welcome.cb9_action}"/>
          </af:form>
        </af:document>
      </f:view>
      <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_welcome-->
    </jsp:root>3.This was my welcome.java backing bean for welcome.jspx page
        public String getAuser() {
            return auser;
        public void setApassword(String apassword) {
            this.apassword = apassword;
        public String getApassword() {
            return apassword;
        public String cb9_action() {
            String returnStr="error";
            System.out.println("Inside loginBtn_action");
            BindingContainer bindings = getBindings();
            OperationBinding operationBinding = bindings.getOperationBinding("checkLoginCredentials1");
            operationBinding.getParamsMap().put("p_user", auser);
            operationBinding.getParamsMap().put("p_pwd", apassword);
        operationBinding.execute();
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            returnStr= "success";
        System.out.println("returnStr= " + returnStr);
               return returnStr;
        }While i run my program no output is displayed!! No logs also been recorded!!
    Could any body pls help me!!

    thank you jhon!
    If i am not using any binding i m getting error as
    javax.el.PropertyNotFoundException: Target Unreachable, 'backing_welcome' returned nullI had used this jspx code
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
      <jsp:directive.page contentType="text/html;charset=UTF-8"/>
      <f:view>
        <af:document id="d1" >
          <af:form id="f1" >
            <af:inputText label="UserName"
                          id="it1" value="#{sessionScope.backing_welcome.auser}"/>
            <af:inputText label="Password"
                          id="it2"
                          value="#{sessionScope.backing_welcome.apassword}"/>
            <af:commandButton text="Login"
                               id="cb1"
                              action="#{sessionScope.backing_welcome.cb9_action}"/>
          </af:form>
        </af:document>
      </f:view>
      <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_welcome-->
    </jsp:root>Give me some guide how to use session scope!! Since i read all the documents i m not getting any proper output

  • Should we try to access session scope in ADF BC ?

    hi
    In the blog post "How to Access Session Scope in ADF BC "
    at http://andrejusb.blogspot.com/2012/01/how-to-access-session-scope-in-adf-bc.html
    Andrejus Baranovskis suggests it is no problem to access session scope in ADF BC using
    Map sessionScope = ADFContext.getCurrent().getSessionScope();But I wonder if this is really a good practice, as it looks very much like breaking the MVC pattern.
    At the same time I wonder where the Oracle documentation says this would be a good or bad idea.
    One starting point could be the ADFContext.getCurrent() method
    at http://docs.oracle.com/cd/E24382_01/apirefs.1112/e17486/oracle/adf/share/ADFContext.html#getCurrent%28%29
    that starts with saying "Gets the ADF context for the current thread. ..." which in a typical deployment scenario of ADF BC might not cause a problem.
    But, I wonder how defensive your programming should be when using the getSessionScope() method in your ADF Business Component code (that implements the Model).
    Ideas and feedback welcome.
    many thanks
    Jan Vervecken

    Hi Shay,
    Reviewing ADFContex methods it seems that this object shouldn't be accessible from BC. Example:
    public static ADFContext initADFContext(java.lang.Object context,
                                            java.lang.Object session,
                                            java.lang.Object request,
                                            java.lang.Object response)
        Initializes the ADFContext for the environment of the specified context.
        Parameters:
            context - the ServletContext or PortletContext of the current execution environment.
            session - the HttpSession or PortletSession of the current execution environment. OPTIONAL.
            request - the HttpServletRequest or PortletRequest of the current execution environment. OPTIONAL.
            response - the HttpServletResponse or PortletResponse of the current execution environment. OPTIONAL.
        Returns:
            the ADFContext that was current when init was invoked. Should be passed back to resetADFContext after the block requiring the ADFContext has completed.Kuba

  • How to remove an object from session with JSF 2.0 + Faceletes

    hi all,
    I have a facelets page which calls a backing bean of session scope. Now when ever i click on this page i want the existing bean object to be removed from the session . In my existing jsp i have a logic something like this to remove the object from session
         <% if (request.getParameter("newid") != null) {
              request.getSession().removeAttribute("manageuserscontroller");
    %>
    Now i have to refactor my jsp to use facelets and i should not be using scriplets anymore . I did try with JSTL but the <c:remove> tag is not supported by facelets.
    Can someone help me how can i refactor this code to work for my facelets?
    I really appreciate your help in advance
    Thank you

    r035198x wrote:
    Redesign things so that the remove is done in a backing bean method rather than in a view page.Exactly that. I tend to cleanup session variables at the start and at the end of a page flow; generally the end is some sort of save or cancel action being invoked through a button but that is application specific.

  • Request and session issues-how to remove a bean from a session

    Hi
    I am implementing copy and move functionality in my application. I need some info to complete that.
    The copy functionality is like this.....From a summary page which consists a Datatable and checkbox...
    I will select a checkbox beside as a copying reference..and click on next..
    In the next page I will get a copying reference bean and a drop down select list box consists of 1-10, I will select some value and click on next. then in the next page, I will get selected no of rows of that copying reference. then when I click on finsh , it will add into database...
    And the next page will open showing .....status of inserting into database..
    the action method I am calling is....
    public String saveCopyingRoutes()
    log.info( "Into saveCopyingRoutes method" );
    String returnStr = UIConstants.RETSTR_SUCCESS;
    // : Get all the rows
    // Read each row and insert each row into database under a particular
    // gateway end point.
    int numRows = table.getRows();
    log.debug( "no of rows-->" + numRows );
    for (int rowIndex=0;rowIndex<numRows;rowIndex++)
    log.debug("value of rowIndex-->"+rowIndex);
    RoutingEntry routingEntry = (RoutingEntry) FacesContext.getCurrentInstance()
    .getExternalContext().getSessionMap().get( "RoutingEntry" );
    try
    // -Need to query using RoutingEntryMgerImpl() class
    new RoutingEntryMgerImpl().addRoutingEntry( routingEntry );
    message = " Verifying Copy sheet " + rowIndex + ".....\n"+
    " Successfully verified datafill in copy sheet" rowIndex".....\n"+
    "Adding copy sheet "+rowIndex+"to the database...\n"
    + " Successfully added copy sheet" rowIndex"to database.....";
    messageList.add( message );
    log.debug("*********************"+messageList.size());
    log.debug("message----->"+message);
    log.debug("*********************");
    catch (NrsProvisionException pe)
    catch (Exception e)
    message = "Unsuccessfully added copy sheet "+rowIndex+"to the database";
    //Show the corresponding error....
    // Throwing generic exception ...?
    e.printStackTrace();
    log.info( "saveCopyingRoutes method return value: " + returnStr );
    return returnStr;
    now the bean is in session scope , let me know how to remove from the session, is there any better way to implement this functionality...

    Read the instructions.

  • How-to remove a jsf backing bean from session?

    How can I find the reference to a backing bean (with session scope) and then remove the bean?
    I may have painted myself into a corner. When most of my pages are navigated to, they get key info from session and then initially populate the page fields. I populate the fields in the constructor with values from the database based on the keys found in session. So the second time a particular page is called the values may be stale or completely unrelated to the page navigated from because the bean already exists and, naturally, the constructor is never called.
    I'm thinking if I could remove the backing bean, jsf wouldn't find it so it would be recreated on subsequent navigations. Since the constructor would be called with every navigation to the page, the values would not be stale or unrelated.
    Any help would be greatly appreciated.
    TIA,
    Al Malin

    //To reset session bean
    FacesContext
         .getCurrentInstance()
         .getApplication()
         .createValueBinding( "#{yourBeanName}").setValue(FacesContext.getCurrentInstance(), null );
    //To get session bean reference
    Object obj = FacesContext
              .getCurrentInstance()
              .getApplication()
              .createValueBinding("#{yourBeanName}")
              .getValue(FacesContext.getCurrentInstance());
    YourSessionBean bean = (YourSessionBean)obj;

  • How to remove Bean from session upon leaving the web page?

    Hi...
    I got the following problem
    I promote a user with a Datatable filled with data, each time the user enters the webpage with the table I go the DB and retrieve all relevant data again (so each time the user gets an OnLine representation of the DB)
    to archive that I defined the bean that pulls data from DB in Request scope. and it worked well... but now i added an option to export the table into Pdf made by a servlet.... now to be able to get the bean from the servlet i had to change the scope of the Bean to Session Scope... and all works fine.. BUT... now the page not showing OnLine representation of the DB.. cause its only created once , cause its inside Session Scope...
    My question is how can I remove the Bean from Session scope upon the user leaving the page (I don't want to remove the bean from session scope on the next called bean of the other page) i want to remove the Bean upon leaving the current web page... Or maybe force the constructor to be executed each time the Page is loaded (as if it was a Request scope bean)....
    Any ideas?
    Thanks ahead!
    Daniel.

    Hi,
    When you are moving to another page, you are performing an action right ?
    (i mean the request moving to Server side), if you do so, then clear the bean object values list.
    for example :
        private List<Integer> intList = new ArrayList<Integer>();
      public void clear()
       intList.clear();
    or
    store a new object in session, when ever u moved to the second page, so that the old object will be no longer
    in use, so it will be garbage collected.Regards,
    Sathya.

  • How to get a parameter from each request in a session scope BackingBean

    While calling my JSF page, I pass an id as parameter in the URL, and in the Backing bean I retrieve it from the request.
    On each request I need to get the id and populate the page accordingly.
    But I am forced to create my Backing Bean in session scope b'cos otherwise ValueChangeListener method does not work properly.
    So where and how do I get the id on each request?
    Pls. help

    What you can do is create it in the request scope like this:
    <managed-bean>
          <managed-bean-name>personBean</managed-bean-name>
          <managed-bean-class>
            com.PersonBean
          </managed-bean-class>
          <managed-bean-scope>request</managed-bean-scope>
           <managed-property>
                 <property-name>id</property-name>
                 <property-class>java.lang.Long</property-class>
              <value>#{param.id}</value>
          </managed-property>
    </managed-bean>And then in the page use a hidden field to set the id in case of a postback (validation error):
    <h:inputHidden id="id" value="#{personBean.id}"/>Does that help you?
    Thomas

  • How to convert processScope to Session Scope.

    Hi,
    Could you please tell me any one, how to convert processScope to Session Scopde.
    because i need to pass 1 processScope value to Servlet. but servlets don't know ProcessScope value. for this i need to convert processScope value into Session scope value.
    Thanks and Regards,
    M. Ramu.

    Hi,
    Could you please tell me, what are the main configurations i need to done about this issue.
    The main requirement is, from Jspx page i need to pass one value to Servlet through xml file.
    as of now i am using processScope in Jspx page, but i passing through xml page to Servlet. As servlet cannot understand processscope, it is throwing null pointer exception.
    Thanks and Regards,
    M. Ramu.

  • How to remove the Sessions used in the application

    Hai Techies,,,
    i am using many number of sessions in my application, for example i am using 5 sessions in reports module
    my application is a web based application
    if can't remove the sessions it contains the huge amount of data , my application is going into mess, and the application performance will be decreased..
    Can anybody tell the solution for this Problem
    How to remove the Sessions used in the application
    Hoping a reply
    Thanks & Regards
    Krishna mangamuri

    Hai Gita,
    i am not able to do the session invalidate method bcoz, i am mainatainting the session from login along with the current userid who is login into the system and putting some of the data in session....
    thats session is to be valid upto when i click on logoff link
    except that i have to remove the sessions in my application
    while navigating from one jsp to another i have to remove the sessions, bit somes times that sessions may be used somewhere
    Can u Understand My problem
    session remove method may also helpful to me but some times it will casue some prob to me
    Is there any other Way to remove the sessions in the Application ????
    Thanks & Regards
    Krishna Mangamuri

Maybe you are looking for