如何在JSP中编写方法并调用它们?

时间:2012-05-10 08:34:54

标签: jsp

以下是我的jsp代码。我是JSP的新手。我在代码

之后显示错误
<body>
<%!
    public ArrayList<ArrayList<Leg>> trip;
    public void routeManager(){
        Location stLoc = new Location(60.2040521,24.96185113,"1023");
        Location endLoc = new Location(60.17936316, 24.92282214 ,"1130");
        RouteRetriever hrr = new RouteRetriever();
        trip = hrr.getRoutes(stLoc, endLoc, false);
    }
%>
<%  routeManager();
    System.out.println("Im here AA");%>
<%= out.println("Hello World:"+hrr.size()) %>
<p>Booooooooooooo!</p>
</body>

错误:

An error occurred at line: 30 in the jsp file: /index.jsp
The method print(boolean) in the type JspWriter is not applicable for the arguments (void)

2 个答案:

答案 0 :(得分:2)

我认为你应该改变

<%= out.println("Hello World:"+hrr.size()) %>

到(只输出)

<%= "Hello World:"+trip.size() %>

或者如果你想使用println(更改&lt;%= to&lt;%):

<% out.println("Hello World:"+hrr.size()); %>

答案 1 :(得分:0)

<%=%>out.println不会在一起。

更改

<% out.println("Hello World:"+hrr.size()); %>

<%=%>是编译Jsp页面时转换为out.write的简写