0

I tried to create arrayList method in JSP as the following :

    <%!
       public int x = 0;
       public ArrayList array = new ArrayList();
       array.add(new ArrayList());
       public ArrayList cidTime (int cid, int w)
       {
            ((ArrayList)array.get(x)).add(cid);
            ((ArrayList)array.get(x)).add(w);
            x++;
            return array;
       }
      %>

but it returned error :

                    Syntax error on token(s), misplaced construct(s) 
                    Syntax error on token "add", = expected after this token

any suggestion?

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
Doni Andri Cahyono
  • 793
  • 5
  • 16
  • 28
  • Don't put Java code in your JSP pages, see http://stackoverflow.com/a/3180202/249327 for many reasons why. Do that in your controller or else create a taglib and put the code there. – nickdos Nov 15 '12 at 05:25
  • 2
    Also, you have asked 8 questions on SO but have not accepted any answers for them (click the tick icon under the vote number on the right side of the answer) - people won't bother answering your questions if you continue this trend. – nickdos Nov 15 '12 at 05:27
  • Learn basic Java first before switching to JSP. This ain't JSP problem – Hardik Mishra Nov 15 '12 at 05:29
  • @nickdos: ok, thanks. I will follow your suggestion. Thanks, anyway. – Doni Andri Cahyono Nov 15 '12 at 05:45

1 Answers1

0

You are using JSP declaration tag <%!. According to the info here it places declarations and methods outside the service method body of the JSP page. Which means that your call array.add(new ArrayList()); is causing the problem because it is not variable declaration or method declaration.

zloster
  • 1,149
  • 11
  • 26