Results 1 to 14 of 14
- 07-15-2010, 05:09 PM #1
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
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)
- 07-16-2010, 03:01 AM #2
When the attribute value "check" is null, (not present in session attributes), this will create a null pointer exception.
Try instead,
or, possibly,Java Code:String checkValue = session.getAttribute("check"); if (checkValue != null && checkValue.equals("jjj")) { ...
Java Code:if ("jjj".equals(session.getAttribute("check"))) {
- 07-16-2010, 12:42 PM #3
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
If session invalidated then sessions vars are null, or...?
- 07-16-2010, 12:48 PM #4
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
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)
- 07-16-2010, 12:49 PM #5
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
trying to empty a shopping cart, session invalidate is appropriate? how check if a session var EXIST ?
- 07-16-2010, 02:01 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,459
- Rep Power
- 16
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.
- 07-16-2010, 02:19 PM #7
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
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.
- 07-16-2010, 02:46 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,459
- Rep Power
- 16
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.
- 07-16-2010, 03:34 PM #9
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
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
- 07-19-2010, 09:45 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,459
- Rep Power
- 16
Have you looked at the API?
Have you looked to see if, possibly, there is a method for removing attributes?
- 07-19-2010, 10:15 AM #11
Member
- Join Date
- Feb 2010
- Posts
- 6
- Rep Power
- 0
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?
- 07-19-2010, 10:29 AM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,459
- Rep Power
- 16
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.
- 07-19-2010, 10:44 AM #13
Member
- Join Date
- Feb 2010
- Posts
- 6
- Rep Power
- 0
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)
- 07-19-2010, 11:04 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,459
- Rep Power
- 16
Similar Threads
-
need help understanding part of code
By mustachMan in forum New To JavaReplies: 7Last Post: 02-09-2011, 07:11 PM -
How to detect browser closing to invalidate a jsp session
By kumar_ps78 in forum JavaServer Pages (JSP) and JSTLReplies: 13Last Post: 08-13-2009, 03:56 PM -
Trouble implementing part of code into GUI
By Flaresplitz in forum New To JavaReplies: 1Last Post: 12-21-2008, 07:51 AM -
How to check a "connection" from datasource is in Container and part of Transaction
By alexendra in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 05-24-2008, 08:51 AM -
How to check a "connection" from datasource is in Container and part of Transaction
By alexendra in forum JDBCReplies: 0Last Post: 05-24-2008, 08:50 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks