Added stop functionality described in text
This commit is contained in:
parent
0a6c7fc822
commit
9d9c7fa6b9
3 changed files with 29 additions and 1 deletions
|
@ -31,6 +31,7 @@ public class Main {
|
|||
s.createContext("/auth", new AuthView());
|
||||
s.createContext("/tree", new TreeView());
|
||||
s.createContext("/object", new ObjectView());
|
||||
s.createContext("/stop", new StopView());
|
||||
s.setExecutor(null);
|
||||
s.start();
|
||||
} catch (IOException e) {
|
||||
|
@ -39,6 +40,7 @@ public class Main {
|
|||
return;
|
||||
}
|
||||
// schließen ist nicht nötig, da beim Beenden die ganze JVM zerstört wird
|
||||
// und der Code hier damit sowieso unreachable ist
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public class StartView implements HttpHandler {
|
|||
response = Defaults.HTMLHEADER + "Startseite<hr>";
|
||||
response +="<h1>Beleg - Startseite!</h1><p>Bitte wähle aus einer der nachstehenden Optionen:</p>";
|
||||
response += "<h2>Studierende</h2>Hier Optionen einfügen!";
|
||||
response += "<h2>Verwaltung</h2><ul><li><a href=\"/tree\">Objektübersicht</a></li></ul>" + Defaults.HTMLFOOTER;
|
||||
response += "<h2>Verwaltung</h2><ul><li><a href=\"/tree\">Objektübersicht</a></li><li><a href=\"/stop\">Server stoppen</a></li></ul>" + Defaults.HTMLFOOTER;
|
||||
|
||||
os = t.getResponseBody();
|
||||
|
||||
|
|
26
src/views/StopView.java
Normal file
26
src/views/StopView.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package hsmw.jotto5.beleg.views;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
public class StopView implements HttpHandler {
|
||||
|
||||
public void handle(HttpExchange t) throws IOException {
|
||||
String response;
|
||||
OutputStream os;
|
||||
|
||||
response = "<h1>Server gestoppt.</h1>";
|
||||
|
||||
os = t.getResponseBody();
|
||||
|
||||
t.sendResponseHeaders(200, response.length());
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
|
||||
// Wir beenden einfach die gesamte JVM. Unschön, aber reicht hier aus.
|
||||
// ACHTUNG: Es wird nicht auf ausstehende Operationen gewartet!
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue