• 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

Hide/show table based on user role

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im quite new to jsp and java and im having a problem with hiding a table based on a users role. So if the user is admin return the resultset and if not hide the resultset. My error is commented in the code below. Any help is appreciated.

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be using the JSTL conditional tags, not Java code in your JSP. Using Java scriptlets in a JSP is an outdated and obsolete technique from over 11 years ago. (And the very type of problem you are having is one of the 17 bazillion reasons that Java code in a JSP has been discredited for over a decade.)

Here are some tips for proceeding:

First of all, rather than using a magic number of -1 to mean anything, use a Boolean value. Magic numbers are just poor practice all around.

Assuming that there is a Boolean property named admin in the session, the condition check simply becomes:

Result sets should never be sent to a JSP. That's another really poor practice that should be avoided. The information from the result set should be copied into normal Java objects and collections before being sent to the JSP.

Hope that helps get you started on a better path.

I often recommend that novices to JSP read the following articles:
  • The Secret Life of JSPs
  • The Front Man

  • and read this JspFaq entry.
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Another point: what's up with this line?
    Firstly, that's not something you really ever need to be doing in a JSP, so I suspect you may be trying to do something else, but I'm not sure what.

    And, be sure to follow Java naming conventions in all code. Variable names should always start with a lowercase letter.
     
    johnny clarke
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Bear Bibeault wrote:Another point: what's up with this line?
    Firstly, that's not something you really ever need to be doing in a JSP, so I suspect you may be trying to do something else, but I'm not sure what.

    And, be sure to follow Java naming conventions in all code. Variable names should always start with a lowercase letter.


    Cheers. Unfortunately I have to write my JSPs this way. I will read through the material and hopefully get it working. Thanks again.
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    johnny clarke wrote:Unfortunately I have to write my JSPs this way.


    Why?

    In any case, check your syntax. It's painful to mix Java with JSP, so it's easy to forget when to include all that gnarly <% markup.
     
    johnny clarke
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Bear Bibeault wrote:Another point: what's up with this line?
    Firstly, that's not something you really ever need to be doing in a JSP, so I suspect you may be trying to do something else, but I'm not sure what.

    And, be sure to follow Java naming conventions in all code. Variable names should always start with a lowercase letter.


    This holds the path to my databse with password and name.
     
    johnny clarke
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Bear Bibeault wrote:

    johnny clarke wrote:Unfortunately I have to write my JSPs this way.


    Why?

    In any case, check your syntax. It's painful to mix Java with JSP, so it's easy to forget when to include all that gnarly <% markup.


    Im intern in company and this is how they do it. Maybe when I take over i can change that.
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Understood. Just be aware that they're using the equivalent of vacuum tubes. It would behoove you to learn more modern ways of working for your next steps.
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    P.S. Pay special attention to line 35.
     
    yeah, but ... what would PIE do? Especially concerning this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic