-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2431d4c
commit 3fe89dc
Showing
5 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 30 additions & 1 deletion
31
tomcat/src/main/java/nextstep/jwp/controller/ViewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,48 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import org.apache.coyote.http11.request.Request; | ||
import org.apache.coyote.http11.response.HttpStatus; | ||
import org.apache.coyote.http11.response.Response; | ||
import org.apache.coyote.http11.servlet.Servlet; | ||
|
||
public class ViewController { | ||
public static Response getIndex(Request request){ | ||
public static Response getLogin(Request request){ | ||
return Response.builder() | ||
.status(HttpStatus.OK) | ||
.contentType("html") | ||
.responseBody(getFile("login.html")) | ||
.build(); | ||
} | ||
|
||
public static Response getRegister(Request request){ | ||
return Response.builder() | ||
.status(HttpStatus.OK) | ||
.contentType("html") | ||
.responseBody(getFile("register.html")) | ||
.build(); | ||
} | ||
|
||
public static Response getVoid(Request request){ | ||
return Response.builder() | ||
.status(HttpStatus.OK) | ||
.responseBody("Hello world!") | ||
.contentType("html") | ||
.build(); | ||
} | ||
|
||
|
||
private static String getFile(String fileName){ | ||
try { | ||
final var fileUrl = Servlet.class.getClassLoader().getResource("static/" + fileName); | ||
final var fileBytes = Files.readAllBytes(new File(fileUrl.getFile()).toPath()); | ||
return new String(fileBytes); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} catch (NullPointerException e){ | ||
return ""; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters