2 Replies Latest reply: Jul 18, 2011 5:47 PM by DrClap RSS

    Using a return value from a boolean function in JSP

    866972
      Hi,

      I have a java class and a function is defined there as :

      public boolean getX(String a) throws Exception {
                some code...
                try {

                     ....
      Y=false;
                     }

                     
                return Y

           }

      }// endclass

      Now i want to use the result in my JSP. From my JSP i am calling:

      mvp= class.getX(String a)
      <%=
      if (mvp==true)
      do
      this
      else
      %>

      Is this the right way to do this ? If no, please let me know how we will be handling this.
        • 1. Re: Using a return value from a boolean function in JSP
          EJP
          Yes, but you don't need the == true part.

          This is one of the most amazingly trivial questions I have ever seen.
          • 2. Re: Using a return value from a boolean function in JSP
            DrClap
            The only case where you should be writing scriptlets in Java is if you're writing a trivial toy application. Otherwise, scriptlets have been obsolete since about 2004 and you should use their replacement, which is JSTL plus EL. However that does require some design, but that's okay since you would be doing some design for any non-trivial application. In this case the design would involve using classes which follow the Java Bean specification; that method doesn't do that.

            However given its clearly made-up name to hide its real function, I'm not going to suggest how you should repair that.