Skip to content

Commit 510b492

Browse files
committed
The servlet now redirects directly after uploading and importing
1 parent cd213d8 commit 510b492

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/main/webapp/java/de/htwb/servlets/ShapeImportServlet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
3535
String userName = request.getParameter("userName");
3636
String tableName = shapeImporter.importFile(shapefile, userName);
3737
ArrayList<ImportedShape> importedShapes = shapeImporter.getImportedShapesFromTable(tableName);
38-
response.setHeader("content-type", "text/json");
39-
response.getWriter().write(String.format("{ \"key\" : %s}", tableName));
38+
response.sendRedirect("ShapeUpdate.html?tableKey="+tableName);
4039

4140
}
4241
catch (Exception ex)

src/main/webapp/js/shapeUpdate.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let baseUrl = "http://localhost:8080/"
22
let classificationDropDown;
33
let importedShapes;
4+
let tableKey;
45

56
$(document).ready(function() {
67
getOHDMInformation();
@@ -12,6 +13,12 @@ function getOHDMInformation()
1213
let xhr = new XMLHttpRequest();
1314
let url = baseUrl + "OHDMInformation";
1415
xhr.open("GET", url, true);
16+
tableKey = getUrlVars()["tableKey"];
17+
18+
if (tableKey)
19+
{
20+
sendDataWithKey(tableKey);
21+
}
1522

1623
xhr.onload = function (e)
1724
{
@@ -64,6 +71,31 @@ function sendData()
6471
xhr.send();
6572
}
6673

74+
function sendDataWithKey(tableKey)
75+
{
76+
77+
let xhr = new XMLHttpRequest();
78+
let url = baseUrl + "ShapeUpdate?tableKey="+tableKey;
79+
tableKey = "";
80+
81+
xhr.open("GET", url, true);
82+
83+
xhr.onload = function (e)
84+
{
85+
if(this.status === 200)
86+
{
87+
let data = this.response;
88+
let dataObj = JSON.parse(data);
89+
90+
console.log(dataObj);
91+
$("#importedShapes").empty();
92+
displayImportedShapes(dataObj.importedShapes);
93+
importedShapes = dataObj.importedShapes;
94+
}
95+
};
96+
xhr.send();
97+
}
98+
6799
function displayImportedShapes(importedShapes)
68100
{
69101
for(let i = 0; i < importedShapes.length; i++)
@@ -211,4 +243,12 @@ function sendUpdateObj(obj)
211243
}
212244
};
213245
xhr.send(formData);
246+
}
247+
248+
function getUrlVars() {
249+
var vars = {};
250+
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
251+
vars[key] = value;
252+
});
253+
return vars;
214254
}

0 commit comments

Comments
 (0)