there are many buttons and they have several values.
when i press button it decreases the total value.
when total is 0 the thank you message is appears.
when total is 0 i need to avoid rthe showing buttons.
how to do this?
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
posted
0
In your Servlet you could set an attribute (request or session attribute) when total=0;
Then you get it on your jsp. If it's null the buttons are visible, if not they aren't.
In the same way. If that attribute you set in the Servlet is null you don't show the message. If it is not, you do show it.
(With the caveat that scriptlets aren't the cleanest way to do this--avoid them, including the bit from lines 19-28. No reason to do that in the JSP, and good reasons not to.
Scriptlets are java code fragments. So, where do YOU think you should place them on?
You may use standard actions or JSTLs on the JSP, but not scriptlets.
Samanthi perera wrote:each request for clicking button it makes a new session
With all due respect, have you every seen the Servlet specification or the documentations of those classes? Which part of the documentation made you believe that getSession() always creates a new session?
Samanthi perera
Ranch Hand
Joined: Jan 08, 2010
Posts: 510
posted
0
I DON'T REMEMBER WHERE.But i heard that if we use
HttpSession session = request.getSession();
it makes a new session for each request.
if we use HttpSession session = request.getSession(false it gets the old session).
Samanthi perera
Ranch Hand
Joined: Jan 08, 2010
Posts: 510
posted
0
i change my servlet.java
now my jsp is like this
but it always print
Thank you very much ccccccccccccccccccccccccccc.
it can't be happen.because it is in c:choose part.how it happens?
Samanthi perera wrote:But i heard that if we use....
Do you thing listening to someone and believing whatever he say is better than going through the specifications or documentations to understand the truth?
Samanthi perera wrote:
HttpSession session = request.getSession();
it makes a new session for each request.
if we use HttpSession session = request.getSession(false it gets the old session)
Samanthi perera wrote:but it always print
Thank you very much ccccccccccccccccccccccccccc.
it can't be happen.because it is in c:choose part.how it happens?
Is their any taglib declaration for the JSTL core in your JSP?
I think you should have a look at the JSTL Tutorial.
Samanthi perera
Ranch Hand
Joined: Jan 08, 2010
Posts: 510
posted
0
if i run this is jps it print both falseee and otherwiseeeeeeeee
Devaka Cooray wrote:Is their any taglib declaration for the JSTL core in your JSP?
I think you should have a look at the JSTL Tutorial.
Samanthi perera
Ranch Hand
Joined: Jan 08, 2010
Posts: 510
posted
0
it is ok now.
i have added
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> to the jsp and add jstl jar file.
not it is working.
when it comes to 0 value it prints thank you.
but after that if i click back button in the browser it shows the buttons and when i click it shows valus as minus valus.
how to avoid this?
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
posted
0
It's ok.
If you set an attribute in a HttpServletRequest object it happens exactly as you are saying.
Once the request is gone, the attribute is gone as well.
Now, if you want, please try to put the attribute total0 in your session instead of in your request.
I mean:
1) Delete the statement:
2) add this one
It works as you expected it should.
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
posted
0
And sorry i would like to add this too:
if you set an attribute in your session, it will stay there during your session life.
So, if your total value is not zero anymore and then you want to show your buttons again during the same session, remember to remove the attribute from your session.
For example, in your servlet you would do like that: