• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

ArrayList throws error in JSP page

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm using Tomcat 5.5.4 with JDK/JRE 1.5.0_04. I have set my environment variables accoring to the directions and have written some other JSP pages that work fine, so I think everything is set up correctly.

Whenever I try to compile and run the following code in a JSP page, I get the error noted below. I am new to Java, but this seems pretty basic to be getting an error... Thanks for your help!

<%
@ page import = "java.util.*";
ArrayList myList = new ArrayList();
%>

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 53 in the jsp file: test.jsp
Generated servlet error:
Syntax error on tokens, Expression expected instead
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<%
@ page import = "java.util.*";
ArrayList myList = new ArrayList();
%>



You can't mix directives and scriplets in this manner.

 
Ben Johnson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem on the name. The only rule I remember seeing was "be nice", so I must have overlooked the stringent naming policy.

Okay, so if I can't mix directives and scriplets in that manner, then what manner can I mix them in? And if no manner at all, how might I accomplish what I'm trying to accomplish?

Thanks,

Ben
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for adjusting your display name so quickly!

The code example at the bottom of my post shows the correct syntax.
 
Ben Johnson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Bear!

I feel like real jerk. Your post was so subtle that I thought for some reason you were reposting my code (perhaps because I forgot the code tags).

Now I realize what you mean about not putting directives and scriptlets within the same set of <%%>.

As a somewhat unrelated aside, any idea why there cannot be a space between the <% and the @ character in the line:



Is the "@" used for supressing the literal output of exceptions that might be thrown? Like I said, I'm new to Java.

Thanks again,

Ben
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the "@" used for supressing the literal output of exceptions that might be thrown? Like I said, I'm new to Java.
Thanks again,
Ben


The <%@ ... %> is a directive tag, not a scriptlet tag.
This isn't really a Java issue as much as it is a JSP specific issue.

I always recommend learning servlets before JSP.
JSP is an abstraction layer that results in machine generated Servlet code.
If you understand the underlying principals (which are as clear as the keys on a piano in basic servlet code) it's a lot easier to figure out what a JSP is really doing.

One tip: A lot of app servers (such as Tomcat) keep the generated servlet code around so you can see exactly what your JSP is being turned into.
[ July 12, 2005: Message edited by: Ben Souther ]
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Ben (the other Ben) said, the <%@ sequence is an introducer for a JSP directive. Other introducers are: <%! <%= and <%. If you put a space in there, the JSP translator gets confused.
 
Ben Johnson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahhh, that makes a lot more sense. I didn't realize that <%!, <%@, etc. were entities entirely separate from the unadorned <%. That is very sound advice, Ben, and I have indeed been focusing my efforts on learning servlets before much else.

Thanks again, to both of you.

Ben
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic