달력

42024  이전 다음

  • 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

JSP 개발 디렉토리와 서비스 디렉토리의 구조의 차이


이클립스를 사용해서 개발을 하는 것은 기존 텍스트 에디터를 이용해서 작업하는 것과 많은 차이를 갖고 있다. 특히 웹 애플리케이션 개발에서는 더 많은 차이가 있게 되는데, 우선 언급해 볼 것이 서비스에 구성된 디렉토리와 개발에 사용되는 디렉토리의 차이점이다.

웹 애플리케이션은 서블릿 스펙에 따라서 디렉토리가 정해진 규칙을 갖고 있다. 

/WEB-INF/ 브라우저를 통해서 접근이 불가능한 웹 애플리케이션 핵심정보들을 포함하고 있는 디렉토리
/WEB-INF/classes/ 패키지에 따른 디렉토리별 class파일과 properties 파일이 위치하는 곳
/WEB-INF/lib/ 웹 애플리케이션에서 사용되는 jar 파일이 존재하는 곳
/META-INF/context.xml 톰캣에서 사용되는 manager를 통한 배포용 웹 애플리케이션 Context정보 파일
브라우저를 통해서 접근 가능한 리소스들은 그 외의 디렉토리에 놓으면 된다.
특히 브라우저의 JVM 위에서 돌아가는 애플릿 class와 관련 jar 들은 /WEB-INF/ 밖에 위치해야 한다.
이 디렉토리들을 묶어서 Context 라고 얘기한다.

서비스와 관련된 디렉토리 구조가 위와 같고, 개발용 디렉토리 구조는 java 파일이라는 특징 때문에 다음과 같이 구성한다.

/src 패키지에 따른 디렉토리별 java 파일과 properties 파일이 존재하는 곳
/WebContent/ 앞에 언급한 브라우저를 통해서 접근 가능한 리소스들. 웹 애플리케이션의 컨텍스트 루트 디렉토리에 해당.
/WebContent/WEB-INF/ 앞에 언급했던 /WEB-INF/ 디렉토리와 같은 성격
/build/classes  /src 하위 자바파일의 컴파일된 class 들이 놓이는 곳. properties 파일은 자동 복사되는 곳.


개발 디렉토리와 WAS의 서비스되는 디렉토리의 매핑 즉 자연스런 연결은 빌드 툴인 ant를 통하거나 Eclipse같은 IDE에서 자동으로 해준다.

이클립스의 경우 Servers 라는 프로젝트가 웹 프로젝트와 별개로 생성이 된다. 여기에서 설정되는 서버의 세팅은 기본적으로 설치된 세팅과 별도로 운영된다. 즉 톰캣이 설치된 디렉토리의 conf 에 있는 설정과는 별개로 Servers하위의 서버별 server.xml 의 파일에 설정된 내용으로 동작이 된다는 뜻이다.
<%= request.getRealPath("/") %> 를 통해서 확인해 보면 이클립스에서 운영하는 디렉토리가 완전히 엉뚱한 곳에 존재함을 알 수 있다. 웹 프로젝트에서 파일을 변경하면 자동으로 파일이 해당 위치로 복사된다.


Posted by 한설림
|

import java.io.*;
import java.net.URLEncoder;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FilenameUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

 

@Controller
public class Test {

 @RequestMapping("/fileView.do")
 public void fileDownLoad(HttpServletRequest request ,HttpServletResponse response) throws IOException {

  System.out.println(request.getParameter("file_id"));
  String getfile = "C:/DATA001/attachFiles/201610/Koala[20161018010740425].jpg";
  //String path = "C:/DATA001/attachFiles/201610/"; //paramMap.get("filePath"); //full경로
     //String fileName =  "Koala[20161018010740425].jpg"; //paramMap.get("fileName"); //파일명
     File f = new File("C:/DATA001/attachFiles/201610/Koala[20161018010740425].jpg");
     String path = f.getParent().toString();
     String fileName = f.getName();
     System.out.println("파일크기 ?" + f.length());
     FilenameUtils.getExtension(getfile);
     System.out.println("path : " + path);
     System.out.println("fileName : " + fileName);
     File file = new File(path+"/"+fileName);
     FileInputStream fileInputStream = null;
     ServletOutputStream servletOutputStream = null;

     try{
         String downName = null;
         String browser = request.getHeader("User-Agent");
         //파일 인코딩
         if(browser.contains("MSIE") || browser.contains("Trident") || browser.contains("Chrome")){//브라우저 확인 파일명 encode

             downName = URLEncoder.encode(fileName,"UTF-8").replaceAll("\\+", "%20");

         }else{

             downName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1");

         }

         response.setHeader("Content-Disposition","attachment;filename=\"" + downName+"\"");
         response.setContentType("application/octer-stream");
         response.setHeader("Content-Transfer-Encoding", "binary;");

         fileInputStream = new FileInputStream(file);
         servletOutputStream = response.getOutputStream();

         byte b [] = new byte[1024];
         int data = 0;

         while((data=(fileInputStream.read(b, 0, b.length))) != -1){

             servletOutputStream.write(b, 0, data);

         }

         servletOutputStream.flush();//출력

     }catch (Exception e) {
         e.printStackTrace();
     }finally{
         if(servletOutputStream!=null){
             try{
                 servletOutputStream.close();
             }catch (IOException e){
                 e.printStackTrace();
             }
         }
         if(fileInputStream!=null){
             try{
                 fileInputStream.close();
             }catch (IOException e){
                 e.printStackTrace();
             }
         }
     }
 }
}

 

Posted by 한설림
|

JQuery checkbox 컨트롤


1. checkbox checked 여부:
id인 경우:  $('input:checkbox[id="checkbox_id"]').is(":checked") == true
name인 경우: $('input:checkbox[name="checkbox_name"]').is(":checked") == true



2. checkbox 전체 갯수(이 경우는 name인 경우만 가능)
$('input:checkbox[name="checkbox_name"]').length;



3. checkbox 선택된 갯수(이 경우는 name인 경우만 가능)
$('input:checkbox[name="checkbox_name"]:checked').length;



4. checkbox 전체 순회하며 처리(동일한 name으로  여러 개인 경우)
$('input:checkbox[name="checkbox_name"]').each(function(){
      this.checked = true; //checked 처리
      if(this.checked){
         alert(this.value);
      }
});



5.checkbox 전체 값을 순회하며, 비교하여 checked 처리
$('input:checkbox[name="checkbox_name"]').each(function(){
     if(this.value == "비교값"){
        this.checked = true;
     }
});



6.checkbox value값 가져오기(단일건)
$('input:checkbox[id="checkbox_id"]').val();



7. checkbox checked 처리하기(단일건)
$('input:checkbox[id="checkbox_id"]').attr("checked", true);



8. checkbox checked 여부 확인(단일건)
$("#checkbox_id").is(":checked");


Posted by 한설림
|

web.xml 설정

경로 : \프로젝트이름\src\main\webapp\WEB-INF\web.xml

<filter>
     <filter-name>sitemesh</filter-name>
     <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
   </filter>

   <filter-mapping>
     <filter-name>sitemesh</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>

</filter>

 

sitemesh3.xml 설정

경로 : \프로젝트이름\src\main\webapp\WEB-INF\sitemesh3.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
  <mapping path="/JSP/KPI/*" decorator="/WEB-INF/jsp/common/decorator/layout.jsp"/>
  <mapping path="/SAMPLE/*" decorator="/WEB-INF/jsp/common/decorator/layout.jsp"/>
  <mapping path="/SERVICE/*" decorator="/WEB-INF/jsp/common/decorator/layout.jsp"/>
  <mapping path="/popup/*" decorator="/WEB-INF/jsp/common/decorator/layout2.jsp"/>

  <mapping path="*/index.jsp" exclude="true"/>    <!-- sitemesh 예외 url  -->

  <mapping path="*/index.do" exclude="true"/>     <!-- sitemesh 예외 url  -->

  <mapping path="*/login_form.html" exclude="true"/>   <!-- sitemesh 예외 url  -->

</sitemesh>

 

pom.xml  설정

경로 : \프로젝트이름\pom.xml

<dependencies>

 <dependency>
   <groupId>org.sitemesh</groupId>
   <artifactId>sitemesh</artifactId>
   <version>3.0.1</version>
  </dependency>

</dependencies>

 

layout.jsp 설정

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE>
<html>
  <head>
   <title>타이틀<sitemesh:write property='title'/></title>
 <meta charset="UTF-8">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">

 <script type="text/javascript" src="/resource/js/jquery-1.12.4.js"></script>
 <script type="text/javascript" src="/resource/js/jquery-ui-1.10.0.js"></script>
 <script type="text/javascript" src="/resource/js/jquery-blockUI.js"/></script>
 <script type="text/javascript" src="/resource/js/jquery.qtip.min.js"/></script>

 <link rel="stylesheet" type="text/css" href="/resource/css/ui_library.css" />
 <link rel="stylesheet" type="text/css" href="/resource/css/ui_library_new.css" />
 <link rel="stylesheet" type="text/css" href="/resource/css/ui_library_ie7.css" />
 <link rel="stylesheet" type="text/css" href="/resource/css/ui_jquery.css" />
     <sitemesh:write property='head'/>
  </head>
  <body>
  <jsp:include page="/decorator/header.do"></jsp:include>
  <jsp:include page="/decorator/left.do"></jsp:include>
     <div class='mainBody'>
      <sitemesh:write property='body'/>
        </div>
    </div>

    <!-- //contents -->
  </div>
 <div>
  <!-- footer-->
 <%@include file="footer.jsp"%>
 <sitemesh:write property='footer'/>
 <!-- //footer-->
 </div>
  </body>
</html>

Posted by 한설림
|