Struts2 静态内容给出404
Struts2 static content giving 404
- 我有apache,配置如下:
重写引擎开启
代理通行证 / <a href="http://demo1.example.com:8080/myApp" rel="nofollow">http://demo1.example.com:8080/myApp</a>
ProxyPassReverse / ....(同上url)
以下是web.xml:
<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>
我有自定义的过滤器,它从 url 中读取子域并在请求中设置:
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);
}
}
我正在使用 struts 2.3.8、Tomcat 6 和 JDK 1.6。我在 webapps/myApp.
下部署了我的应用程序
当我登录到应用程序时,我可以看到以下 urls 的 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 没有在正确的上下文路径中生成静态内容?
最后我找到了这个问题的解决方案..我只是想post在这里,这可能会对某人有所帮助。
<sj:head />
有用,这个标签有助于从 jar 文件复制静态内容。
如果我们将应用程序部署为ROOT,我们只需要添加<sj:head/>
,这会将内容复制到<context>/struts/...
如果我们将 myApp 部署到 webapps,<sj:head/>
将内容复制到 /myApp,但框架搜索“/struts/..”将无法访问。
解决方案:<sj:head>
标签有属性"scriptPath",这告诉框架工作复制内容的位置。我在 jsp 中添加了以下代码修复了问题:
<sj:head compressed="false" scriptPath="/struts/"/>
- 我有apache,配置如下:
重写引擎开启 代理通行证 / <a href="http://demo1.example.com:8080/myApp" rel="nofollow">http://demo1.example.com:8080/myApp</a> ProxyPassReverse / ....(同上url)
以下是web.xml:
<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>
我有自定义的过滤器,它从 url 中读取子域并在请求中设置:
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); } }
我正在使用 struts 2.3.8、Tomcat 6 和 JDK 1.6。我在 webapps/myApp.
下部署了我的应用程序
当我登录到应用程序时,我可以看到以下 urls 的 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 没有在正确的上下文路径中生成静态内容?
最后我找到了这个问题的解决方案..我只是想post在这里,这可能会对某人有所帮助。
<sj:head />
有用,这个标签有助于从 jar 文件复制静态内容。
如果我们将应用程序部署为ROOT,我们只需要添加<sj:head/>
,这会将内容复制到<context>/struts/...
如果我们将 myApp 部署到 webapps,<sj:head/>
将内容复制到 /myApp,但框架搜索“/struts/..”将无法访问。
解决方案:<sj:head>
标签有属性"scriptPath",这告诉框架工作复制内容的位置。我在 jsp 中添加了以下代码修复了问题:
<sj:head compressed="false" scriptPath="/struts/"/>