简体   繁体   English

我可以在 JSP 中创建方法吗?

[英]Can I create methods in JSPs?

Can I write methods in JSPs?我可以在 JSP 中编写方法吗? (Java Server Pages) (Java 服务器页面)

I tried writing a method within the body of the JSP, but my IDE doesn't seem to like it.我尝试在 JSP 的主体中编写一个方法,但我的 IDE 似乎不喜欢它。

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. JSP 只能向用户显示信息,如果您想做一些详细说明,您必须为您重新调用一个 servlet。

Analize and try using this: Everything in your jsp.分析并尝试使用: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";
   }
%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM