반응형

WebLogic이 웹서버와 연결되어 있고 웹서버를 통해 JSP/Servlet에 대한 요청을 백엔드 WLS로 포워딩 하고 있다.

그런데 만약 파일 업로드 기능을 사용해서 WLS 서버로 파일을 저장할 경우 웹서버에서 그것을 보여주려면

WLS쪽에 File Download를 위한 Servlet을 짜야 할 것이다.

그런데 간단한 Tip으로 코딩 없이 설정으로도 해결할 수 있는데... 아래와 같이 WebApp을 하나 만들어 Deploy 하고

weblogic.xml에 다음과 같이 특정 디렉토리(여기서는 파일이 업로드되어 저장되는 디렉토리)를 virtual-directory-mapping으로 잡아 놓고

disable-implicit-servlet-mappings 설정을 통해 JSP 설정을 막아 놓으면 업로드 되는 파일들을 그냥 일반 static contents처럼 다운받을 수 있게 된다.


<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:weblogic-version>12.1.1</wls:weblogic-version>
    <wls:context-root>mywebapp</wls:context-root>
    <wls:virtual-directory-mapping>
        <wls:local-path>/home/oracle/website</wls:local-path>
        <wls:url-pattern>/downloads/*</wls:url-pattern>
    </wls:virtual-directory-mapping>
    <wls:container-descriptor>
        <wls:index-directory-enabled>true</wls:index-directory-enabled>
        <wls:disable-implicit-servlet-mappings>true</wls:disable-implicit-servlet-mappings>
    </wls:container-descriptor>
</wls:weblogic-web-app>


JSP에 대한 실행이 막혔지만 그럼에도 불구하고 보안상 File Upload 프로그램을 작성할 때는 JSP와 같은 코드는 절대로 업로드하지 못하게 하는 것이 바람직 하다.


다음은 실행 결과이다.

Posted by Hey Jerry
,