Results 1 to 14 of 14
  1. #1
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default I tried after session.invalidate(); check if success run a code part(jsp/ht

    I tried after
    session.invalidate();
    check if success run a code part(jsp/html) otherwise run the "else" part but failed repeatly...can you help?
    Java Code:
    <% 
    String oldIDS = session.getId() ; 
    session.setAttribute("check","jjj"); 
    session.invalidate(); 
    
    //session.setAttribute("check2","jjj2");session.isNew()==true  
    //session.getValue("check")!=null 
    
    //String newIDS = session.getId() ; //session.getAttribute("check") == null    
    //oldIDS.equals(newIDS) 
    
    if (session.getAttribute("check").equals("jjj")) {  
             <P>Your cart items get REMOVED SUCCESS!</P> 
    
    
    I get errors like:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /OrderPlantItem-empty.jsp at line 45 
    
    42: 
    43: //String newIDS = session.getId() ; //session.getAttribute("check") == null   oldIDS.equals(newIDS) 
    44: 
    45: if (session.getAttribute("check").equals("jjj")) {  // null request.getParameter("submit") != "" AddChoosePlant %> 
    46:          <P>Your cart items get REMOVED SUCCESS!</P> 
    47:          <form action="OrderPlantItem.jsp"> 
    48:             <table border="1" width="400"> 
    
    
    Stacktrace: 
       org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505) 
       org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410) 
       org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) 
       org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) 
       javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
       org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    When the attribute value "check" is null, (not present in session attributes), this will create a null pointer exception.

    Try instead,
    Java Code:
    String checkValue = session.getAttribute("check");
    if (checkValue != null && checkValue.equals("jjj")) {
     ...
    or, possibly,
    Java Code:
    if ("jjj".equals(session.getAttribute("check"))) {

  3. #3
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    If session invalidated then sessions vars are null, or...?

  4. #4
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default I tried your statements, with error again...

    I tried your statements, with error again...
    Java Code:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /OrderPlantItem-empty.jsp at line 46
    
    43: //String newIDS = session.getId() ; //session.getAttribute("check") == null   oldIDS.equals(newIDS)
    44: 
    45: //if (session.getAttribute("check").equals("jjj")) {  // null request.getParameter("submit") != "" AddChoosePlant 
    46: String checkValue = (String) session.getAttribute("check");
    47: if (checkValue != null && checkValue.equals("jjj")) {
    48: %>
    49: <P>Your cart items get REMOVED SUCCESS!</P>
    
    
    Stacktrace:
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

  5. #5
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    trying to empty a shopping cart, session invalidate is appropriate? how check if a session var EXIST ?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Possibly look at the API?
    It's pretty clear what happens.

    Now, if all you want to do is remove an attribute then look at that API and see if you can figure out which method fits the bill.

    Finally, you really don't want to be doing business logic in a JSP page. JSPs are for display.

  7. #7
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    basically I try empty cart by invalidate session, but wanted check that session no exist so I must check if a session var no exist, how?
    how in a session var=obj=bean, I check if empty or/and not exist, and how set it up to empty or null?

    session is created ONLY if, the first session var created?
    Last edited by lse123; 07-16-2010 at 02:21 PM.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Read the API.
    I gave you the link...read it!

    invalidate() removes all attributes and invalidates the session...you don't want that.
    You just want to remove the contents of the cart...so do that.

  9. #9
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    what exactly to do? Assign session vars to null or ""?

    session is created ONLY if, the first session var is created or, when webuser enters homepage or any page for first time?
    ===========
    isNew()
    true if the server has created a session, but the client has not yet joined

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Have you looked at the API?
    Have you looked to see if, possibly, there is a method for removing attributes?

  11. #11
    lse123j is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default session.removeAttribute(AddChoosePlant); // is it correct for a JSP?

    session.removeAttribute(AddChoosePlant); // is it correct for a JSP?

    how with removeAttribute() ...? this and every session bean considered attribute/var?

    is needed call the
    <jsp:useBean id="AddChoosePlant" scope="session" class="beans.OrderTotals" />
    and after call removeAttribute() (how?)
    in the same emptycart.jsp page? // I have called <jsp:useBean in prior page...

    removeAttribute==set it to null?
    HOW set it to null, if this bean contains vars and other objs(of type bean=line item)? I am tring empty a shopping cart... is you meet this problem in Java/jsp, how you act?

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    I wouldn't be doing all this work in the JSP in the first place.
    The whole emptying of the cart would be done in a servlet.
    JSPs are for display.

    Did you read the API?
    removeAttribute() is pretty clear what it does, and how you use it.

  13. #13
    lse123j is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    by servlet you mean AND bean function???

    may done by tag libraries in jsp...?

    how anyway at last I remove or/and setup to null[zeroed basically] this bean...?
    I read api but...is it session beans like session attributes/vars?
    (even contain other beans these beans)

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

Similar Threads

  1. need help understanding part of code
    By mustachMan in forum New To Java
    Replies: 7
    Last Post: 02-09-2011, 07:11 PM
  2. How to detect browser closing to invalidate a jsp session
    By kumar_ps78 in forum JavaServer Pages (JSP) and JSTL
    Replies: 13
    Last Post: 08-13-2009, 03:56 PM
  3. Trouble implementing part of code into GUI
    By Flaresplitz in forum New To Java
    Replies: 1
    Last Post: 12-21-2008, 07:51 AM
  4. Replies: 0
    Last Post: 05-24-2008, 08:51 AM
  5. Replies: 0
    Last Post: 05-24-2008, 08:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •