• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to avoid show buttons

 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my jsp

this is my calculate.java servlet


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?
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


In the Servlet:


The following is the jsp code:


 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(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.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if it is not good way please tell me a good way?
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, right.

Assuming you have the same request attribute total0 set in your servlet



With the core library the test in your jsp could be written as follows:

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider using Boolean.TRUE, and simplifying the conditional logic to just <c:when test="${total0}">.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in my servlet it get servlet using below code


then each request for clicking button it makes a new session
how to solve this issue?
 
Devaka Cooray
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Devaka Cooray
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Samanthi perera wrote:I DON'T REMEMBER WHERE.


Please KeepItDown.

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)


Please go through the documentation of HttpServletRequest and read it.
 
Devaka Cooray
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i run this is jps it print both falseee and otherwiseeeeeeeee


if i use this tooo same

 
Devaka Cooray
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:



and your buttons will appear again.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic