Je viens de reprendre la maintenance et l'évolution d'un projet en J2EE (jdk 1.4) d'un site de statistique. j'ai pas mal allégé le code et diminué la complexité des algorithme utilisés mais il me reste une chose à faire pour améliorer encore un peu.
j'ai une page jsp qui charge un vector suivant des données d'un fichier TXT. Celui-ci est par la suite affiché à l'aide d'une boucle grâce au taglib. J'affiche aussi un graphe grâce à la librairie JFreechart et une servlet, servlet dans laquelle je refais exactement le même boulot de charger le Vector. auriez vous une idée ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116package exploit.servlets; import java.awt.image.BufferedImage; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.Calendar; import java.util.Properties; import java.util.Vector; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jfree.chart.ChartColor; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.labels.StandardXYItemLabelGenerator; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.StandardXYItemRenderer; import org.jfree.data.xy.DefaultTableXYDataset; import org.jfree.data.xy.XYSeries; import exploit.chart.SimpleChart; import exploit.stats.Stat; import exploit.utils.ExploitCalendar; import exploit.utils.PropertiesHelper; public class CustomerActivityServlet extends HttpServlet { protected static int DEFAULT_HEIGHT = 400; protected static int DEFAULT_WIDTH = 1000; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String customer = request.getParameter("customer"); String service = request.getParameter("service"); //Create Calendar to apply a filter on the stats ExploitCalendar ecalendar = new ExploitCalendar(request.getParameter("dateBegin"), request.getParameter("dateEnd")); Properties globalProperties = null; String globalPropertiesBase = "/resources/global"; try { globalProperties = PropertiesHelper.getPropertyFile(globalPropertiesBase); } catch (Exception e) { e.printStackTrace(); throw new ServletException("Unable to load properties file : " + globalPropertiesBase + ".properties !"); } //retrieves the reporting file and the values String sReportingDirectory = globalProperties.getProperty("reporting.directory"); File reportingFile = new File(sReportingDirectory + "/Webs/" + customer + "_" + service + "_globalActivity.txt"); BufferedReader buff = new BufferedReader(new FileReader(reportingFile)); Vector listStats = new Vector(); String theDate=""; String theValue=""; String line=""; while ((line = buff.readLine()) != null) { try { theDate = line.substring(0, line.indexOf(":")); theValue = line.substring(line.indexOf(":") + 1, line.length()); if (ecalendar.compare(theDate)) { Stat theStatistic = new Stat(); theStatistic.setDate(theDate); theStatistic.setDateStat(ecalendar.getDateCompare()); theStatistic.setValue(theValue); if (customer.equals("UKB")){ theStatistic.setType(Stat.UKB_WEBS_STAT); } if (customer.equals("KluwerCG")){ theStatistic.setType(Stat.KLUWER_CG_WEBS_STAT); } listStats.add(theStatistic); } } catch (Exception estat) { System.err.println("[CustomerActivityAvailabilityServlet] Cannot add statistic:" + line); } } SimpleChart sc = new SimpleChart(); sc.createDataset(listStats); JFreeChart chart = sc.createChart(null, null, "# Hits"); // -- get image from chart BufferedImage image = chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT); // -- Write image in the servlet output stream response.addHeader("Content-Type", "image/png"); BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream()); ChartUtilities.writeBufferedImageAsPNG(bos, image); bos.close(); } catch (Exception e) { response.setHeader("Content-Type", "text/plain"); response.getWriter().println("Error occured while generating graph."); e.printStackTrace(); if (e.getMessage() != null) { response.getWriter().println(e.getMessage()); } else { e.printStackTrace(new PrintWriter(response.getWriter())); } } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

 

 
		
		 
        

 
			
			

 
			 
   



 Passage Vector d'une jsp à une servlet
 Passage Vector d'une jsp à une servlet
				 Répondre avec citation
  Répondre avec citation
Partager