Click to See Complete Forum and Search --> : Problem Displaying out Data in JSP


erickh
10-09-2006, 05:58 AM
can anyone have a look at my code? i got some problems to display it in jsp when i run it with eclipse. can anyone help me on this?? did my java bean declared wrongly? thanks...

this is my java file
package com;

import java.io.File;

import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;

import org.jfree.chart.*;
import org.jfree.data.general.*;

public class StoreData{

private static final long serialVersionUID = 1L;
private final static String filename = "C:\\CountryPieChart.yap";

public static void main(String[] args){
//Delete the existing file
new File(filename).delete();
ObjectContainer db=Db4o.openFile(filename);
try {
StoreAllData();
retrieveAllData();
} finally{
db.close(); //Close the database
}
}

public static void StoreAllData() {
//Delete the existing file
new File(filename).delete();
ObjectContainer db = Db4o.openFile(filename);

//Add data to the database
CountryPeople countryName_1 = new CountryPeople("Malaysia", 100);
CountryPeople countryName_2 = new CountryPeople("New Z", 200);
CountryPeople countryName_3 = new CountryPeople("UK", 300);
CountryPeople countryName_4 = new CountryPeople("Thailand", 400);
CountryPeople countryName_5 = new CountryPeople("Singapore", 50);

//set the value to database
db.set(countryName_1);
db.set(countryName_2);
db.set(countryName_3);
db.set(countryName_4);
db.set(countryName_5);
}

public static void retrieveAllData() {

//Open db
ObjectContainer db = Db4o.openFile(filename);

//Retrieve via empty object
CountryPeople cName = new CountryPeople(null, 0);

ObjectSet result = db.get(cName);

DefaultPieDataset dataset = new DefaultPieDataset();

//retrieve the data from database
while(result.hasNext()) {
CountryPeople obj = (CountryPeople) result.next();
dataset.setValue(obj.getName(), obj.getValue());
//System.out.println(result.next());
}

//Create pie chart
JFreeChart chart = ChartFactory.createPieChart(
"Sample Chart",
dataset,
true,
true,
false);
try {
//save the pie chart as JPEG file
ChartUtilities.saveChartAsJPEG(new File("C:\\CountryPieChart.jpg"), chart, 500, 300);
} catch(Exception e) {
System.out.println("Problem for creating chart");
}
}
}



and this is my jsp file
<jsp:useBean id="myStoreData" class="com.StoreData" scope="page"></jsp:useBean>

<html>
<head><title>Testing Displaying</title>
</head>
<body>

<b>Testing Display Page</b>

<img src="<jsp:getProperty name="myStoreData" property="getFileName" /> /">
</body>

</html>

Uladzimir
10-09-2006, 07:30 AM
Hi!

1) public class StoreData implement java.io.Serializable {

2) property="getFileName" means that you shoud have a getGetFileName() method in the bean :)


And please attach an error log in the future :)

erickh
10-09-2006, 10:39 PM
The error log that i get from executing this is


HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /DisplayWeb.jsp(1,16) equal symbol expected
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

org.apache.jasper.JasperException: /DisplayWeb.jsp(1,16) equal symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:86)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:193)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:143)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:156)
org.apache.jasper.compiler.ParserController.getPageEncodingForJspSyntax(ParserController.j ava:434)
org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.ja va:377)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:169)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:155)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.17


can anyone help me on this? thanks

Uladzimir
10-10-2006, 04:09 AM
Replace
<img src="<jsp:getProperty name="myStoreData" property="getFileName" /> /">
with
<img src="<jsp:getProperty name="myStoreData" property="getFileName" />"/>

erickh
10-10-2006, 11:34 AM
thanks for the info. will try it out and see