Forum Stats

  • 3,853,828 Users
  • 2,264,280 Discussions
  • 7,905,459 Comments

Discussions

Using a return value from a boolean function in JSP

866972
866972 Member Posts: 21
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.

Answers

  • EJP
    EJP Member Posts: 32,920 Gold Crown
    Yes, but you don't need the == true part.

    This is one of the most amazingly trivial questions I have ever seen.
  • DrClap
    DrClap Member Posts: 25,479
    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.
This discussion has been closed.