Fullstack-Study-241204-250625

커리큘럼(12-30/변경)

01. Java
02. git
03. Database 
04. Jsp [Server]

05. HTML,CSS 
07. JS
06. 미니프로젝트-2W

08. SpringFramework , SrpingBoot (v)
09. React JS [Front-end]
10. 중간프로젝트 (1M)
11. Linux 명령어
12. AWS 클라우드
13. DevOps - Docker
14. App - Android
15. 최종프로젝트 (1M)

스프링 프레임워크(Spring Framework)

web.xml

  <servlet>
  	<servlet-name>appServlet</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  	<init-param>
  		<param-name>contextConfigLocation</param-name>
  		<param-value>
  			 /WEB-INF/spring/spring-servlet.xml
  			 /WEB-INF/spring/application-servlet.xml
  		 </param-value>
  	</init-param>
  </servlet>
  
  <servlet-mapping>
  	<servlet-name>appServlet</servlet-name>
  	<url-pattern>/</url-pattern>
  </servlet-mapping>
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>
  		/WEB-INF/spring/root-servlet.xml
  	</param-value>
  </context-param>

spring-servlet.xml

<bean id="aaa" class="com.simple.controller.MainController" />

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="order" value="1" />
		<property name="mappings">
			<!-- 브라우저 /test/aaa요청이 들어오면 aaa빈을 동작시키겠다. -->
			<props>
				<prop key="/test/aaa">aaa</prop>
				<prop key="/test/bbb">aaa</prop>
			</props>
		</property>
</bean>
public class MainController extends MultiActionController{

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String url = request.getRequestURI();
		String contextPath = request.getContextPath();
		String path = url.substring(contextPath.length());
		
		System.out.println(path);
		
		if(path.equals("/test/aaa")) {
			// 반환
			ModelAndView mv = new ModelAndView();
			mv.addObject("data","hell로 월드");
			mv.setViewName("/WEB-INF/views/aaa.jsp");
			return mv; // 디스패처서블릿으로 반환
		}else if(path.equals("test/bbb")) {
			return new ModelAndView("/WEB-INF/views/bbb.jsp");
		}
		return null;
	}
}
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
public class MainController extends MultiActionController{

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String url = request.getRequestURI();
		String contextPath = request.getContextPath();
		String path = url.substring(contextPath.length());
		
		System.out.println(path);
		
		if(path.equals("/test/aaa")) {
			// 반환
			ModelAndView mv = new ModelAndView();
			mv.addObject("data","hell로 월드");
			mv.setViewName("aaa");
			return mv; // 디스패처서블릿으로 반환
		}else if(path.equals("test/bbb")) {
			return new ModelAndView("bbb");
		}
		
		
		return null;
	}
}

<mvc:annotation-driven/>

<context:component-scan base-package="com.simple.controller"/>

<mvc:resources location="/resources/" mapping="/resources/**"/>

메서드에서 파라미터 값의 처리

  1. request.getParameter
  2. @RequestParam사용
  3. VO(DTO)사용(폼 태그의 값을 받아 처리할 수 있는 클래스 생성)
//1st
//	@RequestMapping(value="/param",method=RequestMethod.POST)
//	public String param(HttpServletRequest request) {
//		
//		String id = request.getParameter("id"); // 단일값
//		String[] inter = request.getParameterValues("inter");
//		
//		System.out.println(id);
//		System.out.println(Arrays.toString(inter));
//		
//		return "request/ex02_success";
//	}

// 2nd - @ReuqestParam어노테이션으로 단일값 받기
// @RequestParam은 클라이언트에서 반드시 파라미터값을 넘겨야 함. 그렇지 않으면 거절당함
// required옵션이 필수 여부 지정
// defaultValue가 파라미터가 없을 때 기본값 정의
//	@RequestMapping(value="/param",method=RequestMethod.POST)
//	public String param(@RequestParam("id") String id,@RequestParam("pw") String pw, @RequestParam(value= "name",required=true) String name,@RequestParam(value="inter",required=false,defaultValue="")List<String> inter) {
//		System.out.println(id);
//		System.out.println(inter);
//		
//		return "request/ex02_success";
//	}
	
	// 3nd - 폼의 name값이 vo의 setter와 일치해야 함 멤버변수)
	@RequestMapping(value="/param",method=RequestMethod.POST)
	public String param(MemberVO vo) {
		System.out.println(vo.toString());
		
		return "request/ex02_success";
	}