web.xml
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<beans:bean name="/testing" class="com.spring.test.TestController">
</beans:bean>
</beans:beans>
package com.spring.test;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class TestController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("작동 중");
ModelAndView mv = new ModelAndView();
mv.addObject("test", "테스트 중");
mv.setViewName("test.jsp");
return mv;
}
}
<url-pattern>/*</url-pattern>
-> <url-pattern>/</url-pattern>
-/WEB-INF는 클라이언트에서 절대로 접근할 수 없는 경로임. view 혹은 중요한 파일, 설정 파일은 해당 패스에 위치한다.
mv.setViewName("/WEB-INF/views/test.jsp");
뉴렉(https://www.youtube.com/user/newlec1)을 많이 참고했습니다! 매우 강추 유튜브 입니다!