I have created a simple java project to draw the bar chart taking certain values from text file and named it as ChartAdvancedBar.java
, now i need to invoke it when I press a button in JSP file.
I have added this java project within the libraries of my web project. How can I import this java project to one of my JSP files?
I have added a line:
<%@page import="ChartAdvancedBar.*"%>
But it is giving an error that ChartAdvancedBar
doesn't found.
JSP files get compiled into servlets by the application server (like Tomcat). When you use <%@ page import="ChartAdvancedBar.*" %>
the JSP compiler tries to find ChartAdvancedBar
in the classpath or in the web application's WEB-INF/classes
directory (following the package structure).
But here's the problem:
WEB-INF/classes
or WEB-INF/lib
(if packaged as a JAR).Package your ChartAdvancedBar.java
in a JAR file
Compile your ChartAdvancedBar.java
into a JAR.
Place the JAR inside your web app's /WEB-INF/lib/
directory.
Make sure the class has a proper package declaration, like below
package com.mycompany.chart;
public class ChartAdvancedBar {
// your methods
}
Then in your JSP have below.
<%@ page import="com.mycompany.chart.ChartAdvancedBar" %>`