tags:

views:

17649

answers:

3

I am a complete JSP beginner. I am trying to use a java.util.List in a JSP page. What do I need to do to use classes other than ones in java.lang?

+3  A: 

In the page tag:

<%@ page import="java.util.List" %>
Axeman
Why would you need to import File and IOException classes OR is it that you were just informing the questioner about how to import more than one class in the JSP?
Vijay Dev
Yeah, that was it. I just wanted a class that I could remember offhand. java.lang and java.util classes get pulled in automatically.
Axeman
Axeman, java,lang is OK but java.util classes doesn't get included automatically. or IS it the case with JSP's ????
akjain
+11  A: 

Use the following import statement to import java.util.List:

<%@ page import="java.util.List;" %>

BTW, to import more than one class, use the following format:

<%@ page import="package1.myClass1,package2.myClass2,....,packageN.myClassN;" %>
Sandman
You don't need/want that semicolon at the end.
T.J. Crowder
+3  A: 

FYI - if you are importing a List into a JSP, chances are pretty good that you are violating MVC principles. Take a few hours now to read up on the MVC approach to web app development (including use of taglibs) - do some more googling on the subject, it's fascinating and will definitely help you write better apps.

If you are doing anything more complicated than a single JSP displaying some database results, please consider using a framework like Spring, Grails, etc... It will absolutely take you a bit more effort to get going, but it will save you so much time and effort down the road that I really recommend it. Besides, it's cool stuff :-)

Kevin Day
Ya, know...you were right about violating MVC. Thanks for the info.
jjnguy