728x90

새로운 프로잭트 프리젠테이션 레이어에 Apache Tiles 를 적용 할 것이냐 OpenSymphony Sitemesh를 사용 할것인가 고민을 좀 했다.

과거에 두가지 모두 사용해본 경험으로는
일단 간편하게 적용하기엔 Sitemesh가 편리했지만 구현 방식에 따른 성능이슈때문에 조금 손이 가더라도 Tiles를 선호했던 것 같다.

잠깐 두개를 비교한 블로그 포스팅을 검색해 보고 Tiles 를 선택 하기로 했다.

전자정부프레임워크에 Tiles 관련 종속 jar를 올려보자.

1. /[프로잭트]/pom.xml

properties 추가

 <properties>
  <spring.maven.artifact.version>3.0.5.RELEASE</spring.maven.artifact.version>
  <org.apache.tiles-version>2.2.2</org.apache.tiles-version>
 </properties>

dependency 추가

  <!-- Tiles -->
  <dependency>
   <groupId>org.apache.tiles</groupId>
   <artifactId>tiles-core</artifactId>
   <version>${org.apache.tiles-version}</version>
  </dependency>

  <dependency>
   <groupId>org.apache.tiles</groupId>
   <artifactId>tiles-servlet</artifactId>
   <version>${org.apache.tiles-version}</version>
  </dependency>
  
  <dependency>
   <groupId>org.apache.tiles</groupId>
   <artifactId>tiles-jsp</artifactId>
   <version>${org.apache.tiles-version}</version>
  </dependency>

2. Spring 설정에 View Resolver 수정

/[프로잭트]/src/main/webapp/WEB-INF/config/egovframework/springmvc/dispatcher-servlet.xml 수정

기존 JSTL View 를 2순위로 내리고

Tiles 우선순위를 1로 설정한다.

    <!-- Tiles 2 Resolver -->
 <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
  <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
  <property name="order" value="1" />
 </bean>

 <!-- Tiles 2 Configurer -->
 <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
  <property name="definitions">
   <list>
    <value>/WEB-INF/tiles/default-layout.xml</value>
   </list>
  </property>
 </bean>
 
    <!--
        - This bean configures the 'prefix' and 'suffix' properties of 
        - InternalResourceViewResolver, which resolves logical view names 
        - returned by Controllers. For example, a logical view name of "vets" 
        - will be mapped to "/WEB-INF/jsp/vets.jsp".
    -->
    <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="2
    p:viewClass="org.springframework.web.servlet.view.JstlView" 
    p:prefix="/WEB-INF/jsp/egovframework/rte/" p:suffix=".jsp"/>

 

기존 리졸버의 order를 2로 바꾸는 것을 빼먹지 않도록 한다.

 

3. 프로잭트에 맞는 layouts.xml을 설정한다.

layout 설정은 다음 포스트에.


- 참조 사이트 : http://opensrc.tistory.com/116

728x90
728x90

프로젝트를 하다 보면 현재 요청된 HttpServletRequest를 찾고자

할때가 있습니다.

Service,DAO에서 현재의 request가 필요할때가 있을수 있습니다.

(물론 컨트롤러에 인자로 넘기면 됩니다.)

정확한 케이스를 말하긴 힘들지만 실무에서

꼭 필요할때가 있습니다.

그래서 현재의 Request를 스프링에서 가져 오는 방법을

설명 하고자 합니다.


* RequestContextListener 설정하기


web.xml 파일에 아래와 같이 리스너를 설정 합니다.


<listener>

  <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

</listener>


* 현재 HttpServletRequest 객체 가져오는 함수 만들기


public static HttpServletRequest getCurrentRequest() {


       ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder

               .currentRequestAttributes();


       HttpServletRequest hsr = sra.getRequest();

       return hsr;

}


출처 : http://beyondj2ee.tumblr.com/

728x90

'프로그래밍 > spring' 카테고리의 다른 글

@Aspect Annotation을 이용한 로그인 세션 관리  (0) 2016.04.29
Spring3에서 Tiles2 설정  (0) 2016.04.21
Apache Titles 적용하기  (0) 2016.04.21
messageConverter 방법  (0) 2016.04.20
DefaultAnnotationHandlerMapping  (0) 2016.04.20
728x90

spring 3.2 이상에서 사용할 수 있는 messageConverter 방법

오늘 json 데이터를 가져오는 방법을 코드로 짜보면서 도움이 될 거 같아 정리했다.

servlet.xml 에 보면 "컨트롤러에서 넘어온 데이터(JSON 같은)를 messageConverter로 사용할 수 있는 방법 1" 과

"컨트롤러에서 넘어온 데이터(JSON 같은)를 messageConverter로 사용할 수 있는 방법 2" 가 있다.

원하는 방법으로 사용하면 된다.


아래는 Ref는 AnnotationMethodHandlerAdapter가 deprecated 된 이유를 알 수 있는 좋은 블로그가 있어서 참조했다.

Description Ref :)

http://javaiyagi.tistory.com/357

Spring 3.0 의 DefaultAnnotationHandlerMapping 과 AnnotationMethodHandlerAdapter가  Spring 3.1 에선 @Deprecated 되고, 

대신 RequestMappingHandlerMapping과 RequestMappingHandlerAdapter 로 바뀌었다.

이유인즉슨, Controller 의 요청이 메소드 단위로 세분화 되면서 , 

DefaultAnnotationHandlerMapping 이 AnnotationMethodHandlerAdapter로 handler 를 전달해줄 때, 문제가 생겼기 때문이다 .


pom.xml

<!-- jackson Json -->

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-databind</artifactId>

<version>2.7.3</version>

</dependency>

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-core</artifactId>

<version>2.7.3</version>

</dependency>


<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-annotations</artifactId>

<version>2.7.3</version>

</dependency>

<dependency>

    <groupId>org.codehaus.jackson</groupId>

    <artifactId>jackson-core-asl</artifactId>

    <version>1.9.13</version>

</dependency>


<dependency>

    <groupId>org.codehaus.jackson</groupId>

    <artifactId>jackson-mapper-asl</artifactId>

    <version>1.9.13</version>

</dependency>


servlet-context.xml

<!-- 컨트롤러에서 넘어온 데이터(JSON 같은)를 messageConverter로 사용할 수 있는 방법 2 -->

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">

<property name="messageConverters">

    <util:list list-class="java.util.ArrayList">

<ref bean="mappingJackson2HttpMessageConverter"/>

    </util:list>

</property>

</bean>

<bean id="mappingJackson2HttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

<property name="supportedMediaTypes">

    <list>

<value>text/html;charset=UTF-8</value>

<value>application/json;charset=UTF-8</value>

    </list>

</property>

</bean>

728x90
728x90

스프링 2.5 부터는 Controller 인터페이스를 구현하지 않은 클래스도 어노테이션을 사용하여 컨트롤러로 사용할 수 있게 되었다. 이를 위해 스프링은 @Controller, @RequestMapping 등 컨트롤러를 구현하는데 필요한 어노테이션을 제공하고 있다.

어노테이션을 이용하여 컨트롤러를 구현할 때는 요청 URL 매핑을 @RequestMapping 어노테이션을 이용하여 설정한다.
@RequestMapping 어노테이션을 처리하기 위해서 DefaultAnnotationHandlerMapping 을 HandlerMapping 으로 등록해 주어야 한다.

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"
p:alwaysUseFullPath="true" />


그런데 DispatcherServlet 이 사용하는 설정 파일에 별도의 HandlerMapping 명시를 하지 않으면, DispatcherServlet 은 기본적으로 DefaultAnnotationHandlerMapping 을 등록하므로 디폴트로 설정 파일에 명시를 하지 않아도 된다.

(만약 DispatcherServlet 이 사용하는 스프링 설정 파일에 HandlerAdapter 를 등록했다면, 추가적으로 AnnotationMethodHandlerAdapter 를 빈으로 등록해주어야 어노테이션을 이용한 컨트롤러가 정상 동작함)


이제 @Controller 어노테이션에 대해서 알아보자. @Controller 어노테이션은 클래스 타입에 적용되며, @Controller 를 붙이면 해당 클래스를 웹 요청을 처리하는 컨트롤러로 사용할 수 있다.

@Controller
public class HelloController {
...
}


컨트롤러로 사용하기 위해 @Controller 가 적용된 클래스는 <bean> 태그에서 스프링 빈으로 등록해주면 된다.

<bean id="helloController" class="...package.HelloController" />


아니면 <context:component-scan> 태그를 이용하여 @Controller 를 적용한 클래스를 자동으로 로딩할 수 있다.

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context2.5.xsd">
    
    <context:component-scan
        base-package="...package" />


</beans>


위에서 component-scan 영역은 base-package 까지만 잡아주면 된다. 클래스 명을 제외한 패키지 이름까지만.

정리해보면 @Controller 어노테이션을 적용한 클래스는 <bean> 태그를 이용하거나 <context:component-scan> 태그를 이용하여 등록하면, DefaultAnnotationHandlerMapping 을 통해 컨트롤러로 사용이 되는 것이다.

 

이제는 @RequestMapping 어노테이션을 이용한 요청 매핑에 대해서 알아보자.

@RequestMapping 어노테이션은 컨트롤러가 처리할 요청 URL 을 명시하는데 사용되며, 클래스나 메서드에 적용된다.

@RequestMapping 을 클래스에 적용하지 않고 메서드에만 적용할 경우 각각의 메서드가 처리할 요청 URL 을 명시하게 된다.

@Controller
public class RequestController {

    @RequestMapping("/test/mapping1.do")
    public String mappingFirst(@RequestParam("id") String id, @RequestParam("pwd") String pwd, ModelMap modelMap) {
        // 로직 처리와 리턴 구문
    }

    @RequestMapping("/test/mapping2.do")
    public String mappingSecond(@RequestParam("id") String id, @RequestParam("pwd") String pwd, ModelMap modelMap) {
        // 로직 처리와 리턴 구문
    }
    ...
}

다수의 메서드에 @RequestMapping 을 적용하면, MultiActionController 처럼 한 개의 컨트롤러에서 다수의 요청을 처리할 수가 있다.

그리고 @RequestMapping 의 method 엘리먼트를 이용하면 처리할 수 있는 Http Method 를 지정할 수도 있다.

@RequestMapping(value="/test/mapping1.do", method=RequestMethod.POST)
public String mappingSomething(...) {...}

@RequestMapping 을 클래스 타입에 적용하게 되면, 해당 컨트롤러 클래스는 지정한 URL 만을 처리할 수 있다.
이 경우 메서드에 적용되는 @RequestMapping 은 더 이상 URL 명시를 할 수 없고, method, params 엘리먼트만 지정할 수 있게 된다.


출처 : http://northface.tistory.com/

728x90
728x90

1. jQuery로 선택된 값 읽기

 

$("#selectBox option:selected").val();

$("select[name=name]").val();

 

2. jQuery로 선택된 내용 읽기

 

$("#selectBox option:selected").text();

 

3. 선택된 위치

 

var index = $("#test option").index($("#test option:selected"));

 

4. Add options to the end of a select

 

$("#selectBox").append("<option value='1'>Apples</option>");

$("#selectBox").append("<option value='2'>After Apples</option>");

 

5. Add options to the start of a select

 

$("#selectBox").prepend("<option value='0'>Before Apples</option>");

 

6. Replace all the options with new options

 

$("#selectBox").html("<option value='1'>Some oranges</option><option value='2'>MoreOranges</option>");

 

7. Replace items at a certain index

 

$("#selectBox option:eq(1)").replaceWith("<option value='2'>Someapples</option>");

$("#selectBox option:eq(2)").replaceWith("<option value='3'>Somebananas</option>");

 

8. 지정된 index값으로 select 하기

 

$("#selectBox option:eq(2)").attr("selected", "selected");

 

9. text 값으로 select 하기

 

$("#selectBox").val("Someoranges").attr("selected", "selected");

 

10. value값으로 select 하기

 

$("#selectBox").val("2");

 

11. 지정된 인덱스값의 item 삭제

 

$("#selectBox option:eq(0)").remove();

 

12. 첫번째 item 삭제

 

$("#selectBox option:first").remove();

 

13. 마지막 item 삭제

 

$("#selectBox option:last").remove();

 

14. 선택된 옵션의 text 구하기

 

alert(!$("#selectBox option:selected").text());

 

15. 선택된 옵션의 value 구하기

 

alert(!$("#selectBox option:selected").val());

 

16. 선택된 옵션 index 구하기

 

alert(!$("#selectBox option").index($("#selectBox option:selected")));

 

17. SelecBox 아이템 갯수 구하기

 

alert(!$("#selectBox option").size());

 

18. 선택된 옵션 앞의 아이템 갯수

 

alert(!$("#selectBox option:selected").prevAl!l().size());

 

19. 선택된 옵션 후의 아이템 갯수

 

alert(!$("#selectBox option:selected").nextAll().size());

 

20. Insert an item in after a particular position

 

$("#selectBox option:eq(0)").after("<option value='4'>Somepears</option>");

 

21. Insert an item in before a particular position

 

$("#selectBox option:eq(3)").before("<option value='5'>Someapricots</option>");

 

22. Getting values when item is selected

 

$("#selectBox").change(function(){

           alert(!$(this).val());

           alert(!$(this).children("option:selected").text());

});


728x90
728x90

시인은 하늘의 별이 되어 아스라이 세상을 비춥니다.
청운동 인왕산 자락에 위치한 별을 사랑한 시인 윤동주,
시인이 남긴 유일한 유품 유작,
원고지 위로 흐르는 글씨 속에서 마음을 읽습니다.
별이 하늘에 떠있듯,
글씨 위로 시인의 마음이 떠 있습니다.
눈물이 젖어들어 볼을 타고 흐릅니다.
나라를 사랑하고
나라말을 사랑하며
나라 사람을 사랑했지만,
나라를 잃은 슬픔은 그 울분은 한 줄 글로 달래지거나,
별을 그윽히 바라보며 노래해도 위로가 되지 못했을 것입니다.
오늘이 여기서,
곱게 써내려간 나라글을 읽으며 가슴 벅차 웁니다.
너무나 당연하게 쓰고 있고
너무나 당연한 세상으로 치부하고 있는 
내 자신이 초라하기 그지 없습니다.
별이 바람에 스치듯
시인의 넋을 기린 언덕에는 
분홍빛, 하얀빛 벚꽃이 바람에 스치웁니다.
화사하게 물든 그 곳에 서서 
저 멀리 북간도 땅을 바라봅니다.
투명한 유리벽 뒤 편에 서서 
나라글 사랑하는 이 보신다면 
빛 바랜 흑백 사진 속에 담겨있으 신 
모습을 한 당신께서 미소 지으며
나라를 사랑하고
나라 글을 사랑하며
나라 사람을 사랑하던 마음을 별빛으로 흩날리시겠죠.
어제가 그립듯이
그 그리움은 회색빛 구름되어 
시인의 마음 담은 조그마한 문학관 위로 
촉촉한 단비로 적셔지겠죠.
사랑합니다.
당신이 거기에 계셨기에
우리는 이곳에 있습니다.
사랑합니다.

728x90

'에세이' 카테고리의 다른 글

  (0) 2020.03.20
약속  (0) 2019.09.17
봄비  (0) 2016.04.07
공백  (0) 2016.04.06
삭제  (0) 2016.04.06
728x90










728x90

'하늘을 사랑한 사람 여행기' 카테고리의 다른 글

전주한옥마을 2  (0) 2016.05.06
전주한옥마을_풍남문  (0) 2016.05.06
윤동주 시인님 문학관에 가다  (0) 2016.04.09
외도 여행 두번째  (0) 2015.05.31
외도여행 첫번째  (0) 2015.05.31
728x90











728x90

'하늘을 사랑한 사람 여행기' 카테고리의 다른 글

전주한옥마을_풍남문  (0) 2016.05.06
윤동주 시인님의 언덕에 가다  (0) 2016.04.09
외도 여행 두번째  (0) 2015.05.31
외도여행 첫번째  (0) 2015.05.31
축령산 정상에서  (0) 2015.02.08

+ Recent posts