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

안녕하세요.

출처 : https://winmargo.tistory.com/103


진행하기 위에선 DB에 파일 정보가 담겨져 있어야 합니다.


pom.xml

1
2
3
4
5
<dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
          <version>1.3.2</version>
        </dependency>
cs


FileController.java

1
2
3
4
5
6
7
8
9
10
11
12
13
@RequestMapping("/fileDown.do")
    public ModelAndView download(@RequestParam("filecol")String filecol){
        
        logger.info("@@@@@@@@@@@@@@@FileDown(1) START@@@@@@@@@@@@@@@");
        
        String fullPath = filecol;
         
        File file = new File(fullPath);
        
        logger.info("@@@@@@@@@@@@@@@FileDown(1) END@@@@@@@@@@@@@@@");
         
        return new ModelAndView("download""downloadFile", file);
    }
cs


servlet-context.xml

1
2
3
4
5
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
              <property name="order" value="0"/>
    </bean>
    
    <bean id="download" class="com.java.spring.util.FileDownload"/>
cs



FileDownload.java

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class FileDownload extends AbstractView {
    public void Download(){
        
        setContentType("application/download; utf-8");
         
    }
 
    @Override
    protected void renderMergedOutputModel(Map<String, Object> model,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        // TODO Auto-generated method stub
        
        File file = (File)model.get("downloadFile");
        System.out.println("DownloadView --> file.getPath() : " + file.getPath());
        System.out.println("DownloadView --> file.getName() : " + file.getName());
         
        response.setContentType(getContentType());
        response.setContentLength((int)file.length());
         
        //String userAgent = request.getHeader("User-Agent");
         
        //boolean ie = userAgent.indexOf("MSIE") > -1;
         
        String fileName = null;
         
        //if(ie){
        //브라우저 정보에 따라 utf-8변경
        if(request.getHeader("User-Agent").indexOf("MSIE"> -1){
             
            fileName = URLEncoder.encode(file.getName(), "utf-8");
                         
        } else {
             
            fileName = new String(file.getName().getBytes("utf-8"));
        }// end if;
        
        response.setHeader("Content-Disposition""attachment; filename=\"" + fileName + "\";");
        response.setHeader("Content-Transfer-Encoding""binary");
        OutputStream out = response.getOutputStream();
        FileInputStream fis = null;
        
        //파일 카피 후 마무리
        try {
            fis = new FileInputStream(file);
            FileCopyUtils.copy(fis, out);
        } catch(Exception e){
            e.printStackTrace();
        }finally{
            if(fis != null){
                try{
                    fis.close();
                }catch(Exception e){}
            }
        }// try end;
        out.flush();
        
    }
}
cs


home.jsp 

해당 파일이 db로 뿌려지고 있다면..

1
2
3
4
5
function fileDown(file){
            location.href = "http://localhost:8080/spring/fileDown.do?filecol="+encodeURI(file);
        }
 
<td onclick="fileDown('${list.FILECOL }')">${list.FILECOL }</td>
cs


감사합니다.


'SPRING' 카테고리의 다른 글

SPRING PROCEDURE 사용하기 1  (0) 2019.04.01
SPIRNG EXCEL UPLOAD 하기  (1) 2019.04.01
Spring FileUpload 하기  (0) 2019.03.28
Spring Excel down하기  (0) 2019.03.28
SPRING JSTL 이용해서 Spring 값 뿌리기  (0) 2019.03.27
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

안녕하세요.

퍼온글 : https://mkil.tistory.com/273

pom.xml

1
2
3
4
5
<dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
          <version>1.3.2</version>
        </dependency>
cs


servlet-context.xml

1
2
3
4
5
<!-- MultipartResolver -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
      <property name="maxUploadSize" value="100000000"/>
      <property name="maxInMemorySize" value="100000000"/>
    </bean>
cs


home.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$("#fileUpForm").change(function(){
                var form = $("#fileUpForm")[0];
                var data = new FormData(form);
                $.ajax({
                   enctype:"multipart/form-data",
                   method:"POST",
                   url: './fileUp.do',
                   processData: false,   
                   contentType: false,
                   cache: false,
                   data: data,
                   success: function(result){  
                       alert("업로드 성공!!");
                   }
                });
            });
<form name="fileUpForm" id="fileUpForm" enctype="multipart/form-data" method="POST" action="./excelDown.do">
    <input type="file" id="upFile" name="upFile" value="엑셀 업로드" />
</form>
cs


commUtil.java

1
2
3
4
//uuid생성 
    public static String getUuid() { 
        return UUID.randomUUID().toString().replaceAll("-"""); 
    }
cs


FileController.java

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@RequestMapping(value = "/fileUp.do", method = RequestMethod.POST)
    public void ExcelUp(HttpServletRequest req, HttpServletResponse rep){
        logger.info("@@@@@@@@@@@@@@@FileUp START@@@@@@@@@@@@@@@");
        
        //파일이 저장될 path 설정 
        String path = "D://"
        Map returnObject = new HashMap(); 
        
        try { // MultipartHttpServletRequest 생성 
            MultipartHttpServletRequest mhsr = (MultipartHttpServletRequest) req; 
            Iterator iter = mhsr.getFileNames(); 
            MultipartFile mfile = null
            String fieldName = ""
            List resultList = new ArrayList(); // 디레토리가 없다면 생성 
            File dir = new File(path); 
            
            if (!dir.isDirectory()) { 
                dir.mkdirs(); 
            } 
            
            // 값이 나올때까지
            while (iter.hasNext()) { 
                fieldName = iter.next().toString(); // 내용을 가져와서 
            mfile = mhsr.getFile(fieldName); 
            String origName; 
            origName = new String(mfile.getOriginalFilename().getBytes("8859_1"), "UTF-8"); //한글꺠짐 방지 // 파일명이 없다면 
            
            if ("".equals(origName)) { continue; } // 파일 명 변경(uuid로 암호화) 
            
                String ext = origName.substring(origName.lastIndexOf('.')); // 확장자
                String saveFileName = CommUtil.getUuid() + ext;//getUuid() + ext; // 설정한 path에 파일저장 
                File serverFile = new File(path + File.separator + saveFileName); 
                mfile.transferTo(serverFile); 
                Map file = new HashMap(); 
                file.put("origName", origName); 
                file.put("sfile", serverFile); 
                resultList.add(file); 
                
                //DB에 들어갈만한 건들
                System.out.println("복호화된 파일 이름 : "+serverFile.getName()); //복호화된 파일 이름 
                System.out.println("물리적 저장 경로  : "+serverFile.getAbsolutePath()); //물리적 저장 경로 
                System.out.println("파일 크기 : "+serverFile.length()); //파일 크기 
                System.out.println("원래 파일 명 : "+origName); //원래 파일 명
 
            }
            
            returnObject.put("files", resultList); 
            returnObject.put("params", mhsr.getParameterMap()); 
            
        } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block 
            e.printStackTrace(); 
        }catch (IllegalStateException e) { // TODO Auto-generated catch block 
            e.printStackTrace(); 
        } catch (IOException e) { // TODO Auto-generated catch block 
            e.printStackTrace(); 
        }
        logger.info("@@@@@@@@@@@@@@@FileUp End@@@@@@@@@@@@@@@");
    }
cs




감사합니다.

'SPRING' 카테고리의 다른 글

SPIRNG EXCEL UPLOAD 하기  (1) 2019.04.01
SPRING FILE DOWNLOAD하기  (0) 2019.03.28
Spring Excel down하기  (0) 2019.03.28
SPRING JSTL 이용해서 Spring 값 뿌리기  (0) 2019.03.27
SPRING resources 사용하기  (0) 2019.03.27
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

퍼옴글 : https://jun7222.tistory.com/310


스프링 프레임워크 + tomcat 8.0 + oracle 11g 에서 혼자 로컬로 DB를 사용할 때는 아무 문제가

없다가 여러 인원이 DB서버 하나를 사용하게 될 때 발생했던 오류

close()를 해줘야 하는데 안하는게 쌓이다 보니 결국 오류가 뿜음..


ORA-12519, Error preloading the connection pool, no appropriate service handler found 보인다.



경고: Unexpected exception resolving reference

java.sql.SQLException: Error preloading the connection pool

at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2084)

Caused by: java.sql.SQLException: Listener refused the connection with the following error:

ORA-12519, TNS:no appropriate service handler found

at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419)

org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)

... 22 more

Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:

ORA-12519, TNS:no appropriate service handler found

 

at oracle.net.ns.NSProtocol.connect(NSProtocol.java:386)

at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1054)

at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:308)

... 31 more

경고: Unexpected exception resolving reference

java.sql.SQLException: Error preloading the connection pool

at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2084)

at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getLogWriter(BasicDataSource.java:1587)

Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:

ORA-12519, TNS:no appropriate service handler found

 

at oracle.net.ns.NSProtocol.connect(NSProtocol.java:386)

at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1054)

at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:308)

... 79 more



오류 해결방법

1. close()를 해준다.


2. SELECT * FROM V$SESSION WHERE OSUSER != 'SYSTEM';  으로 점유하는 것을

확인하여 이상이 있는지 체크





이 글에서 소개할 방법은 3번

3. processes의 할당량을 늘려준다.


select * from v$resource_limit where resource_name = 'processes';

위 내용을 입력하여 현재 사용중인 수가 할당보다 많으면 위 오류를 나온다.


현재 32 최대 36 할당 100 




먼저, cmd를 실행한다.

sqlplus /nolog

SQL> conn /as sysdba


SQL>alter system set processes=200 scope=spfile;

               값은 적당하게~


SQL> shutdown immediate;

SQL> startup;




재시작까지 완료되고 다시 확인을 하면




위처럼 allocation, limit 값이 늘어난 걸 확인할 수 있다.



출처: https://jun7222.tistory.com/310 [leverage 블로그]

'DATABASE > ORACLE' 카테고리의 다른 글

ORACLE PROCEDURE 쿼리 COMMIT 또는 ROLLBACK  (0) 2017.02.16
ORACLE FOR LOOP구문  (0) 2017.02.16
ORACLE WHILE문과 LOOP문  (0) 2017.02.16
ORACLE 프로시저 IF문과 EXCEPTION처리방법  (0) 2017.02.16
ORACLE PLSQL  (0) 2017.02.12

+ Recent posts