2016-07-15 76 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/"/>