Struts2 .action扩展导致CSS,JavaScript和Struts Dojo中断 [英] Struts2 .action extension causing CSS, JavaScript and Struts Dojo to break

查看:320
本文介绍了Struts2 .action扩展导致CSS,JavaScript和Struts Dojo中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经在Struts 2.1.8上运行了一段时间,所有的Struts操作都按照预期的方式工作,即,使用没有扩展名的操作名称来呈现Struts操作的href。

We have been running on Struts 2.1.8 for some time and all Struts actions have been working as expected, i.e. href's to the Struts actions are rendered with the action name with no extension.

这是JSP代码设置的链接:

Here is the JSP code that set's up the links:

<ul id="top_menu">
  <li id="itemHome" class="active"><s:a action="viewHome">Home</s:a></li>
  <li><s:a action="viewSearch">Search</s:a></li>
  <li><s:a action="viewBookMarks">My Bookmarks</s:a></li>
  <li><s:a action="viewSupport">Support</s:a></li>
</ul>

链接正确呈现到 http:// localhost / viewHome http:// localhost / viewSearch 等在2.1.8

The links rendered correctly to http://localhost/viewHome, http://localhost/viewSearch, etc. under 2.1.8

我们刚刚升级到Struts 2.2.1(一个已经检查所有版本从这到v2.3.4.1),现在看到Struts动作链接呈现为 http://localhost/viewHome.action http://localhost/viewSearch.action 等。

We just upgraded to Struts 2.2.1 (an have checked all versions from this up to v2.3.4.1) and are now seeing Struts actions links are rendering as http://localhost/viewHome.action, http://localhost/viewSearch.action, etc.

我的研究表明一般建议的解决方案是使用

My research has shown that the general suggested solution is to use

<constant name="struts.action.extension" value=""/>

删除.action后缀。虽然这会使网址正确呈现,但会引起意外的副作用。 Struts现在认为每个URL都是包含对.css,.png等的请求的操作。

in struts.xml to remove the .action suffix. Whilst this makes the URLs render correctly it is causing an unexpected side effect. Struts now thinks every URL is an action including requests for .css, .png, etc.

我的web.xml中的过滤器映射没有改变。虽然它发送/ *到Struts我们没有看到这种行为2.1.8

My filter-mapping in web.xml has not changed. And although it sends /* to Struts we didn't see this behavior under 2.1.8

<filter>
   <filter-name>struts2</filter-name>
   <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>   
</filter>

<filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

为了抵消这一点,我不得不使用 excludePattern 来停止Struts尝试将这些请求视为操作。

To counteract this I've had to use the excludePattern to stop Struts trying to treat these requests as actions.

<constant name="struts.action.excludePattern" value="/index.html,/images/.*,/js/.*,/css/.*"/>

尽管如此,最后一个障碍是我的日志中充满了Struts标签请求中的错误被处理为Struts操作。当我将这些URI添加到排除模式中时,Struts Dojo标签在某些页面似乎不起作用。

Whilst this works, the last hurdle is that my logs are full of errors from Struts tags requests that are being handled as Struts actions. When I add these URI's to the exclude pattern then Struts Dojo tags don't seem to be working in some pages.

受影响的struts.xml的部分是: p>

The parts of struts.xml affected are:

<constant name="struts.devMode" value="true" />
<!-- Set URL's to have no .action extension -->
<constant name="struts.action.extension" value=""/>
<constant name="struts.action.excludePattern" value="/index.html,/images/.*,/js/.*,/css/.*"/>

日志中的Struts错误示例是:

And an example of the Struts errors in the log is:

2012-09-26 17:12:57,984 [http-bio-8080-exec-9] ERROR org.apache.struts2.dispatcher.Dispatcher- Could not find action or result
/struts/dojo/struts_dojo.js
There is no Action mapped for namespace [/] and action name [struts_dojo.js] associated with context path []. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:501)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)

m不知道struts的Dojo请求是真实的URI还是虚拟的或其他的东西。

I'm not sure if the struts Dojo requests are real URI's or virtual or something else.

在这一点上,我已经跳过了几个圈子来修复什么本质上是一个简单的问题,从URL中删除.action扩展名,因为回到2.1.8 JAR解决了一切,但如果可能,我决心找到一条路。

It feels at this point that I've jumped through quite a few hoops to fix what is essentially a simple problem of removing the .action extension from URL's given that going back to the 2.1.8 JAR solves everything but I'm determined to find a way forward if possible.

任何帮助都非常感谢。

推荐答案

尝试使用struts动作exstension以逗号这样的b $ b < constant name =struts.action.extensionvalue =,/>

从struts2属性文件:

Try to use struts action exstension with comma like this
<constant name="struts.action.extension" value=","/>.
From the struts2 properties file:


DefaultActionMapper使用
您可以提供一个逗号分隔列表,例如struts.action.extension = action,jnlp,do
空白扩展允许您匹配目录列表以及纯动作名称
,而不会干扰静态资源,可以将其指定为空字符串
之前的逗号例如struts.action.extension =或struts.action.extension = x,y,z ,,
struts.action.extension = action ,,

Used by the DefaultActionMapper You may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do The blank extension allows you to match directory listings as well as pure action names without interfering with static resources, which can be specified as an empty string prior to a comma e.g. struts.action.extension=, or struts.action.extension=x,y,z,, struts.action.extension=action,,

这篇关于Struts2 .action扩展导致CSS,JavaScript和Struts Dojo中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆