반응형
Notice
Recent Posts
Recent Comments
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
관리 메뉴

차근차근

전자정부프레임워크(egov) ajax 설정 방법 본문

개발

전자정부프레임워크(egov) ajax 설정 방법

철산92 2019. 11. 17. 10:43
반응형

pom.xml 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
        <!-- ajax start-->
        <dependency>       
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>       
            <version>2.4</version>       
            <classifier>jdk15</classifier>
        </dependency>
         
        <dependency>
             <groupId>org.codehaus.jackson</groupId>
             <artifactId>jackson-mapper-asl</artifactId>
             <version>1.9.13</version>
        </dependency>
        
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.5.1</version>
        </dependency>
        
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.1</version>
        </dependency>
        <!-- ajax end-->

 

dispatcher-servlet.xml

1
2
3
4
5
    <!-- jsonView -->
    <bean id="beanNameResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/>
        <property name="contentType" value="application/json;charset=UTF-8"></property>
    </bean>

 beans안에 삽입

 web.xml

1

2

3

4

5

6

7

8

9

    <servlet-mapping>

        <servlet-name>action</servlet-name>

        <url-pattern>*.do</url-pattern>

    </servlet-mapping>

  

    <servlet-mapping>

        <servlet-name>action</servlet-name>

        <url-pattern>*.ajax</url-pattern>

    </servlet-mapping>

web.xml에 ajax패턴 추가

control

1
2
3
4
5
6
7
8
9
10
    @RequestMapping(value = "/uploadAjax.ajax", method = RequestMethod.POST)
    public ModelAndView fileAjax(MultipartFile file,Model model) throws Exception {
        Map<String,Object> hashMap = new HashMap<>();
        hashMap.put("orgFileName", file.getOriginalFilename());
        hashMap.put("fileSize", file.getSize());
        hashMap.put("orgFileType", file.getContentType());
        
        ModelAndView modelAndView = new ModelAndView("jsonView",hashMap);
        return modelAndView;
    }

ModelAndView(dispatcher-servlet.xml에서 ajax설정한 ID ,ajax에서 받을값)

 

jsp

1
2
3
4
5
6
7
8
9
10
11
    $.ajax({
        url:"<c:url value='/uploadAjax.ajax'/>",
        data:formData,
        dataType:'text',
        processData:false,
        contentType:false,
        type:'POST',
        success: function(data){
            console.log(data);
        }
    });

jsp에서 ajax보내기

반응형
Comments