2016-07-15 74 views
1
  1. 我有Apache和配置如下:
    RewriteEngine On ProxyPass/http://demo1.example.com:8080/myApp ProxyPassReverse/....(same url as above)
  2. 以下是web.xml中:Struts2的靜態內容給404

    <filter> 
        <filter-name>struts2</filter-name> 
        <filter- class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
    </filter> 
    <filter> 
        <filter-name>UrlFilter</filter-name> 
        <filter-class>com.rts.utils.UrlFilter</filter-class> 
    </filter> 
    <filter-mapping> 
        <filter-name>UrlFilter</filter-name> 
        <url-pattern>*.action</url-pattern> 
    </filter-mapping>  
    <filter-mapping> 
        <filter-name>struts2</filter-name> 
        <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    
  3. 我已經定製過濾器,從URL中讀取subdoman並在請求中設置:

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 
    HttpServletRequest httpReq = (HttpServletRequest) request; 
    if(httpReq.getServerName() != null && httpReq.getServerName().indexOf(".") != -1) { 
         request.setAttribute("subdomain",...); 
         chain.doFilter(request, response); 
        } 
        } 
    
  4. 我使用的是struts 2.3.8,Tomcat 6 & JDK 1.6。我在webapps/myApp下部署了我的應用程序。

當我登錄到應用程序中,我可以看到404下面的網址和我的網頁不能正常加載:

http://example.com/myApp/struts/js/base/jquery-1.8.3.js 

如果我嘗試了上面的URL(直接在瀏覽器)不給「對myApp」,像下面我收到劇本

http://example.com/struts/js/base/jquery-1.8.3.js 

這意味着struts2中不生成正確的contextPath靜態內容?

+0

你有什麼其他的過濾器?你能複製你的代碼的相關部分嗎? – yeppe

+0

@yeppe感謝您的回覆..是的,我有另一個自定義的過濾器來讀取子域名。下面是該代碼:' \t UrlFilter \t <濾波器級> com.rts.utils.UrlFilter <濾波器映射> \t UrlFilter \t * .action ' – Raju

+0

編輯你的問題,從web.xml中把相關的代碼/應用/等 – yeppe

回答

0

最後我找到了解決這個問題的方法..我只是想在這裏發帖,這可能有助於某人。

<sj:head />會訣竅,這是標籤有助於從jar文件複製靜態內容。

如果我們部署應用程序的根,我們只需要添加<sj:head/>,這將複製內容到<context>/struts/...

如果我們<sj:head/>複製內容到/對myApp部署對myApp到的webapps,但框架搜索「/ struts/..」,這將不會是aviv。

解決方案:<sj:head>標記具有屬性「scriptPath」,這表示框架工作在哪裏複製內容。我下面加在我的JSP代碼解決了該問題:

<sj:head compressed="false" scriptPath="/struts/"/>