How to Import Classes in Jsp

How do you import classes in JSP?

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" %>

Import a class from a jsp page to another jsp page

Short: Not possible.

Longer: I could imagine few very dirty hacks to achieve what you want, but the whole conception is wrong. If you have classes to be shared between different JSP pages, these classes should be externalized, compiled independently, and then referenced (imported) as such in such JSP pages.

Importing own java files in jsp

JSP file can import files with class extension and not java extension.

Class file is a compiled java file.

You need to compile you java file which will create FooBar.class

One option is to save FooBar.class file in a jar under /WEB-INF/lib

Second option is save FooBar.class inside your classes folder under relevant pack for example if your package is a.b /WEB-INF/classes/a/b/FooBar.class

Import java class to Jsp in Maven project

Your .java files must be in

\src\main\java

Is there any way to import classes to the jsp page (jsp+eclipse+java)

Ctrl+shift+o does not work in eclipse for jsp file although you can just try writing

<%@page import="com

and then crtl+space it should provide you all the classes and package available.

One more thing...

Try this:

Type YourClassName anywhere on your JSP which you want to import and just hit crtl+space it will automatically add following line <%@page import="package.YourClassName"%>



Related Topics



Leave a reply



Submit