admin

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1) src/main/webapp/WEB-INF/web.xml을 열어 추가 한다.

web.xml의 파일의 내용.

<?xml version="1.0" encoding="utf-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns="http://java.sun.com/xml/ns/javaee"

         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

         id="WebApp_ID" version="2.5">


    <display-name>FrameWork</display-name>

    

   <!--

- Location of the XML file that defines the root application context.

- Applied by ContextLoaderListener.

-->

    <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>classpath:spring/applicationcontext.xml</param-value>

    </context-param>


    <listener>

        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    

    

    <!--

- Servlet that dispatches request to registered handlers (Controller implementations).

-->

    <servlet>

        <servlet-name>dispatcherServlet</servlet-name>

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>/WEB-INF/mvc-config.xml</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>

        <servlet-name>dispatcherServlet</servlet-name>

        <url-pattern>/</url-pattern>

    </servlet-mapping>

</web-app>

2) dispatcherServlet에서 설정한 mvc-config.xml파일을 설정한다.



src/main/java에 com.my.framework.common.controller 패키지를 추가하고 "<context:component-scan base-package="com.my.framework.common.controller"/>" controller 스캔 설정을 한다.

그리고 view에 해당하는 jsp 폴더를 추가하고 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

       <property name="prefix" value="/jsp/"/>

       <property name="suffix" value=".jsp"/>

</bean>

<mvc:annotation-driven />


3) applicationcontext.xml 설정



<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans 

                   http://www.springframework.org/schema/beans/spring-beans.xsd

               http://www.springframework.org/schema/context 

               http://www.springframework.org/schema/context/spring-context.xsd

               http://www.springframework.org/schema/tx

               http://www.springframework.org/schema/tx/spring-tx.xsd

http://www.springframework.org/schema/jdbc 

http://www.springframework.org/schema/jdbc/spring-jdbc.xsd

               http://www.springframework.org/schema/aop 

http://www.springframework.org/schema/aop/spring-aop.xsd

               http://www.springframework.org/schema/jee 

                   http://www.springframework.org/schema/jee/spring-jee-3.0.xsd

                   http://www.springframework.org/schema/oxm 

http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">


</beans> 

4) sample 프로그램 작성 및 확인 하기

4-1) sample.jsp 파일 작성.

  src/java/webapp/jsp/sample.jsp 파일을 작성

4.2) Controller 작성

com.myframework.common.controller.SampleController의 내용

package com.my.framework.common.controller;

import java.util.Map;


import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;


@Controller

public class SampleController {


public SampleController(){}

@RequestMapping(value="/jsp/sample",method=RequestMethod.GET, produces ="text/html;charset=UTF-8")

public ModelAndView viewCode(@RequestParam Map<String,String> params, HttpServletRequest request ,HttpServletResponse response)

{

ModelAndView modelAndView = new ModelAndView();

modelAndView.setViewName("/jsp/sample");

return modelAndView;

}

}

5) tomcat Server 실행.


    실행히 위와 같이 에러가 난다면 Proejct에서 오른쪽마우스 클릭 Properties를 실행 

5-1) Deployment Assembly 실행 



6) sample 호출.



'0.SpringFrameWork > 1.환경설정하기' 카테고리의 다른 글

eclipse에서 tomcat Server 실행하기  (0) 2016.02.26