전자정부 프레임워크는 기본으로 회원전용 서비스이다.
로그인을 해야만 사용할 수 있는데 blog처럼 누구나 와서 읽을 수 있는 서비스를 하려고 하면 좀 복잡하다.
간단하게 *.do 형태로 호출되는 서비스와
*.bog 로 호출되는 서비스를 나누어서 *.blog에서는 로그인 체크를 안하면 된다.
추가방법.
web.xml 에 추가 : 기존에 action 이라는 servlet이 있으므로 그 밑에 추가
<servlet> <servlet-name>blog</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/config/blog/springmvc/blog*.xml</param-value> </init-param> / </servlet> <servlet-mapping> <servlet-name>blog</servlet-name> <url-pattern>*.blog</url-pattern> </servlet-mapping> |
blog_servlet.xml 추가 : web.xml 에 정의된 경로에 추가
이것은 egov-com-servlet.xml 을 copy 한 것이고
기본 package 경로를 수정한다.
<context:component-scan base-package="사용할package명.blog"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/> </context:component-scan> |
Java Source로 Controller, Service, Repository 등을 생성한다.
(일단은 Contoller만 만들어서 되는지 확인하자)
@Controller public class BlogController {
private ApplicationContext applicationContext;
private static final Logger LOGGER = LoggerFactory.getLogger(BlogController.class);
private Map<Integer, IncludedCompInfoVO> map;
public void afterPropertiesSet() throws Exception {}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; LOGGER.info("BlogController setApplicationContext method has called!"); }
@RequestMapping("/index.blog") public String index(ModelMap model) { return "blog/BlogMain"; } |
index.blog 가 호출될 때 보여줄 jsp Page를 만든다
WEB-INF/jsp/blog/BlogMain.jsp
WEB-INF 밑에 index.jsp 에서
<jsp:forward page="/index.do"/> 를 호출하게 되어 있으므로
<jsp:forward page="/index.blog"/>로 바꾸어 준다.