-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateGraph.java
More file actions
65 lines (56 loc) · 2.29 KB
/
GenerateGraph.java
File metadata and controls
65 lines (56 loc) · 2.29 KB
1
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
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.opencsv.CSVReader;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/generateGraph")
public class GenerateGraph extends HttpServlet {
private static final long serialVersionUID = 205242440643911308L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try {
String[] filterList = request.getParameterValues("category");
System.out.println("filterList" +Arrays.asList(filterList));
Reader reader = Files.newBufferedReader(Paths.get(ApplicationConstatnts.UPLOAD_DIR + File.separator + request.getSession().getAttribute("fileName")));
CSVReader csvReader = new CSVReader(reader);
String[] line;
List<String> col1List = new ArrayList<>();
List<String> col2List = new ArrayList<>();
boolean skipHeader=true;
int col1Index= Integer.parseInt(filterList[0]);
int col2Index= Integer.parseInt(filterList[1]);
while ((line = csvReader.readNext()) != null) {
if(skipHeader) {
request.setAttribute("col1Name", line[col1Index]);
request.setAttribute("col2Name", line[col2Index]);
skipHeader=false;
continue;
}
col1List.add(line[col1Index]);
col2List.add(line[col2Index]);
}
reader.close();
csvReader.close();
//System.out.println("col1List "+col1List);
//System.out.println("col2List "+col2List);
request.setAttribute("generateGrpah", "YES");
request.setAttribute("col1List", col1List);
request.setAttribute("col2List", col2List);
} catch (Exception e) {
}
getServletContext().getRequestDispatcher("/HomePage.jsp").forward(request, response);
}
}