Saturday, August 15, 2009

JSP importing class and jar files

Using java class files in jsp files

1. Put the class files in WEB-INF/classes/ folder

2. Import the class as <%@page import="."%>

3. Call that class as you would do in a normal java program

eg:

<%@page import="test.Hello"%>

<%
Hello heloo = new Hello();
String myName = heloo.SayName();
out.println("From scriptlet : "+ myName + "\n");
%>





Using a jar file in jsp

1. Put the jar file in lib folder.

2. Import the jar file as <%@page import=".*"%>

3. Call the class as .

eg:

<%@page import="jarTest.*"%>

<%
jartest.Main m = new jartest.Main();
String name = m.getName("Pinda");
out.println(name);
%>


No comments: