0

I tried created below jsp.. but it is just keep on loading not showing any result... any help on optimizing this jsp Or let me know if this code is correct and it will show an applet on the browser.

As the code shows I am taking dynamic value from database and want to show them in pie chart on browser.

<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import= "javax.swing.*" %>
<%@ page import= "java.awt.*" %>
<%@ page import="java.awt.image.*" %>
<%@ page import="org.jfree.chart.*" %>
<%@ page import="org.jfree.chart.axis.*" %>
<%@ page import="org.jfree.chart.entity.*" %>
<%@ page import="org.jfree.chart.labels.*" %>
<%@ page import="org.jfree.chart.plot.*" %>
<%@ page import="org.jfree.chart.renderer.category.*" %>
<%@ page import="org.jfree.chart.urls.*" %>
<%@ page import="org.jfree.data.category.*" %>
<%@ page import="org.jfree.data.general.*" %>
<%@ page import= "org.jfree.chart.title.TextTitle" %>
<%@ page import= "org.jfree.data.general.DefaultPieDataset" %>
<%@ page import="org.jfree.ui.*" %>

<html>
<head>
</head>
<body>
<%
ResultSet rs = null;
Connection con =null;
Statement st=null;
try
{
String queryactive1 = null;
String queryactive2= null;
String queryactive3 = null;
String queryactive4 = null;
String queryactive5 = null;
String queryactive6 = null;
String queryactive7 = null;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con= DriverManager.getConnection("jdbc:sqlserver://newine:3468;instanceName=MSSQL2005","eGActiveDB_762","eGActiveDB_762");
st = con.createStatement();

%>
<p style="text-align:center"><B><u>Pie Chart Showing Case Count</u></B></p>
<%
queryactive1="SELECT count(a.case_id)as case_count , b.owner from EGPL_CASE a Right Outer Join (Select distinct OWNER from EGPL_CASE where owner in (1047,1213)) b on b.owner =a.owner and a.when_created BETWEEN '2011-01-01 00:00:00' AND '2011-01-01 1:59:59' group by b.OWNER order by b.owner";

rs=st.executeQuery(queryactive1);
rs.absolute(2);
int ravi_case=rs.getInt("case_count");
rs.absolute(4);
int pradeep_case=rs.getInt("case_count");



%>
<%

JPanel panel = new JPanel(new GridLayout(2, 2));
DefaultPieDataset dataset = new DefaultPieDataset();
DefaultPieDataset dataset1 = new DefaultPieDataset();
dataset.setValue("January "+ravi_case, ravi_case);

dataset1.setValue("January "+pradeep_case,pradeep_case);

JFreeChart chart1 = ChartFactory.createPieChart("Ravi Case", dataset, false, false, false);
JFreeChart chart2 = ChartFactory.createPieChart("Pradeep Case", dataset1, false, false, false);

panel.add(new ChartPanel(chart1));
panel.add(new ChartPanel(chart2));
panel.setPreferredSize(new Dimension(800, 600));


%>
<p style="text-align:center"><B><u>BAr Chart</u></B></p>


<%


}
catch(Exception e)
{
String error = e.toString();
e.printStackTrace();
%>

Error is : <%=error%>
<%
}
finally{
rs = null;
st = null;
con = null;
}
%>
</body>


</html>
user1030815
  • 11
  • 1
  • 1

1 Answers1

0

No, it's not correct at all. An applet is a Java program, packaged in a jar file, that the browser downloads and executes in the client browser.

A JSP is some dynamically composed page that executes on the server, and outputs HTML which is rendered in the client browser.

If this code would display a JPanel (which id doesn't : it just constructs one), the panel would be displayed on the server screen, where the code is executed.

Finally, a JSP should not contain Java code for decades, but should use the JSTL and other custom tags. Read How to avoid Java code in JSP files?.

Read the Java tutorial about applets, try to create an applet displaying a graph with purely static data and embed it into a static HTML page, then make a JSP that contains the same code as the static JSP to embed the applet, and finally think of a way for the applet to communicate with the server to get the data allowing it to display the graph.

Community
  • 1
  • 1
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255