스트라이프는 파일 업로드 라이브러리로 cos 라이브러리를 사용한다. 이것은 다른 라이브러리에 의존하지 않는다.

반면 apache 의 file-upload 는 commons-io 패키지에 의존한다. 또한 라이센스 문제로 인해 cos 를 사용한다.

 

web.xml 의 스트라이프 필터에 멀티파트 인터셉터를 추가한다.

[web.xml]

<init-param>
<param-name>MultipartWrapper.Class</param-name> <param-value>
net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper </param-value> </init-param>

파일찾기 버튼이 추가될 jsp 파일엔 다음의 태그핸덜를 사용한다.

 

[upload.jsp]

<stripes:form>
...
<stripes:file name="newAttachment"/>
...
</stripes:form>

그리고 파일을 받을 액션 클래스에는 FileBean 클래스를 받는다.
[uploadActionBean.java]
private FileBean newAttachment;
public FileBean getNewAttachment() return newAttachment;
}
public void setNewAttachment(FileBean newAttachment) {
this.newAttachment = newAttachment; }

파일 업로드 크기 제한

파일 업로드시에 업로드 크기를 제한할 수 있다. 기본값으로 10메가바이트로 지정되어있다.
web.xml 의 StripesFiler 부분에 FileUpload.MaximumPostSize 설정을 추가한다.
설정값은 1kb,10mb,10gb 등으로 사용할 수 있다. 다음은 2기가로 제한한 예이다.

[web.xml]
<filter>
<display-name>Stripes Filter</display-name> <filter-name>StripesFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
<init-param>
<param-name>ActionResolver.Packages</param-name> <param-value>kr.or.ehc.kg.web</param-value> </init-param>
<init-param>
<param-name>Interceptor.Classes</param-name> <param-value>net.sourceforge.stripes.integration.spring.SpringInterceptor</param-value>
</init-param>
<init-param> <param-name>MultipartWrapper.Class</param-name> <param-value>net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper</param-value>
</init-param>
<init-param> <param-name>FileUpload.MaximumPostSize</param-name> <param-value>2gb</param-value>  </init-param>
</filter>


참조 : http://www.stripesframework.org/display/stripes/File+Uploads

이 글은 스프링노트에서 작성되었습니다.

+ Recent posts