정적인 detail.html, list.html 파일을 jsp로 바꾸기
패키지 만들기
컨트롤러 만들기
ListController.java
package com.newlecture.web.controller.notice;
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 ListController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
// TODO Auto-generated method stub
ModelAndView mv = new ModelAndView("notice/list"); //객체생성
//mv.setViewName("/WEB-INF/view/notice/list.jsp"); //데이터 담은거 setting
return mv;
}
}
detailController.java
package com.newlecture.web.controller.notice;
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 detailController implements Controller{
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
// TODO Auto-generated method stub
ModelAndView mv = new ModelAndView("notice/detail"); //객체생성
//mv.setViewName("/WEB-INF/view/notice/detail.jsp"); //데이터 담은거 setting
return mv;
}
}
url mappting 시켜주기
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<bean name="/index" class="com.newlecture.web.controller.IndexController" />
<bean name="/notice/list" class="com.newlecture.web.controller.notice.ListController" />
<bean name="/notice/detail" class="com.newlecture.web.controller.notice.detailController" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:resources location="/static/" mapping="/**"></mvc:resources>
</beans>
실행결과
VIew 페이지 집중화의 필요성
헤더의 내용을 수정하면 모든 부분에 바꿔줘야 한다.
페이지에 있는 공동 분모를 집중화해야 한다.
Tiles를 써야 한다.