Can I write methods in JSPs? (Java Server Pages)
I tried writing a method within the body of the JSP, but my IDE doesn't seem to like it.
CodePudding user response:
JSP can only show information to user, if you want to do some elaboration you have to re-call a servlet that to that for you.
CodePudding user response:
Analize and try using this: Everything in your jsp.
But i recommend you that if your a gonna use methods, use classes instead. They are safer and loads quite faster when calling them.
<%
//Your main logic
out.print(myMethod());
%>
<html>
your client side content
</html>
<%!
public String myMethod(){
return "Method called successfully";
}
%>