java reflection init
This commit is contained in:
49
reflect/pom.xml
Normal file
49
reflect/pom.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>reflect</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>reflect</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<junit.version>5.7.0</junit.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
27
reflect/src/main/java/com/example/reflect/HelloServlet.java
Normal file
27
reflect/src/main/java/com/example/reflect/HelloServlet.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.example.reflect;
|
||||
|
||||
import java.io.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.servlet.annotation.*;
|
||||
|
||||
@WebServlet(name = "helloServlet", value = "/hello-servlet")
|
||||
public class HelloServlet extends HttpServlet {
|
||||
private String message;
|
||||
|
||||
public void init() {
|
||||
message = "Hello World!";
|
||||
}
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
response.setContentType("text/html");
|
||||
|
||||
// Hello
|
||||
PrintWriter out = response.getWriter();
|
||||
out.println("<html><body>");
|
||||
out.println("<h1>" + message + "</h1>");
|
||||
out.println("</body></html>");
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.example.reflect.controller;
|
||||
|
||||
public class UserController {
|
||||
|
||||
public void join(){
|
||||
System.out.println("join() 함수 호출");
|
||||
}
|
||||
public void login(){
|
||||
System.out.println("login()함수 호출");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.example.reflect.filter;
|
||||
|
||||
import com.example.reflect.controller.UserController;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Dispatcher implements Filter {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
|
||||
throws ServletException, IOException {
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
HttpServletResponse response = (HttpServletResponse) resp;
|
||||
|
||||
// System.out.println("컨텍스트 : " + request.getContextPath());
|
||||
// System.out.println("식별자주소 : " + request.getRequestURI());
|
||||
// System.out.println("전체주소 : " + request.getRequestURL());
|
||||
|
||||
String endPoint = request.getRequestURI().replaceAll(request.getContextPath(), "");
|
||||
|
||||
UserController userController = new UserController();
|
||||
if(endPoint.equals("/join")){
|
||||
userController.join();
|
||||
}else if(endPoint.equals("/login")){
|
||||
userController.login();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
reflect/src/main/webapp/WEB-INF/web.xml
Normal file
19
reflect/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
|
||||
<filter>
|
||||
<filter-name>dispatcher</filter-name>
|
||||
<filter-class>com.example.reflect.filter.Dispatcher</filter-class>
|
||||
</filter>
|
||||
|
||||
<!-- 해당 필터는 모든 필터들 중에서 가장 마지막에 실행되어야 하는 필터 -->
|
||||
<!-- 필터 순서는 filter-mapping 여러개 있을 때 위에서 부터 순차적으로 실행됨 -->
|
||||
<filter-mapping>
|
||||
<filter-name>dispatcher</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
</web-app>
|
||||
13
reflect/src/main/webapp/index.jsp
Normal file
13
reflect/src/main/webapp/index.jsp
Normal file
@@ -0,0 +1,13 @@
|
||||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>JSP - Hello World</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%= "Hello World!ㅎㅇ" %>
|
||||
</h1>
|
||||
<br/>
|
||||
<a href="hello-servlet">Hello Servlet</a>
|
||||
</body>
|
||||
</html>
|
||||
BIN
reflect/target/classes/com/example/reflect/HelloServlet.class
Normal file
BIN
reflect/target/classes/com/example/reflect/HelloServlet.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
5
reflect/target/reflect-1.0-SNAPSHOT/META-INF/MANIFEST.MF
Normal file
5
reflect/target/reflect-1.0-SNAPSHOT/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,5 @@
|
||||
Manifest-Version: 1.0
|
||||
Created-By: IntelliJ IDEA
|
||||
Built-By: 김우진
|
||||
Build-Jdk: 11.0.8
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
19
reflect/target/reflect-1.0-SNAPSHOT/WEB-INF/web.xml
Normal file
19
reflect/target/reflect-1.0-SNAPSHOT/WEB-INF/web.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
|
||||
<filter>
|
||||
<filter-name>dispatcher</filter-name>
|
||||
<filter-class>com.example.reflect.filter.Dispatcher</filter-class>
|
||||
</filter>
|
||||
|
||||
<!-- 해당 필터는 모든 필터들 중에서 가장 마지막에 실행되어야 하는 필터 -->
|
||||
<!-- 필터 순서는 filter-mapping 여러개 있을 때 위에서 부터 순차적으로 실행됨 -->
|
||||
<filter-mapping>
|
||||
<filter-name>dispatcher</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
</web-app>
|
||||
13
reflect/target/reflect-1.0-SNAPSHOT/index.jsp
Normal file
13
reflect/target/reflect-1.0-SNAPSHOT/index.jsp
Normal file
@@ -0,0 +1,13 @@
|
||||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>JSP - Hello World</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%= "Hello World!ㅎㅇ" %>
|
||||
</h1>
|
||||
<br/>
|
||||
<a href="hello-servlet">Hello Servlet</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user