java 用于 Web 应用程序问题的 Struts2 web.xml 文件过滤器 jar

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15125276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:34:24  来源:igfitidea点击:

Struts2 web.xml file filter jar for web application issue

javaxmlweb-applicationsstruts2

提问by JD87

I am currently in the middle of trying to create a small web application using the Struts2 framework. (In eclipse)

我目前正在尝试使用 Struts2 框架创建一个小型 Web 应用程序。(日食中)

I am currently trying to use a filter in the web.xml (in the WEB-INF folder) file to transfer control over to the struts.xml file (in the src folder). (This is what I saw in a tutorial).

我目前正在尝试使用 web.xml(在 WEB-INF 文件夹中)文件中的过滤器将控制权转移到 struts.xml 文件(在 src 文件夹中)。(这是我在教程中看到的)。

The code I am using for the filter is as follows:

我用于过滤器的代码如下:

<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> 

I don't think Tomcat is finding the class in the JAR files for the filter as I keep getting this following error:

我不认为 Tomcat 在过滤器的 JAR 文件中找到类,因为我不断收到以下错误:

java.lang.NoClassDefFoundError: com/opensymphony/xwork2/ActionContext at org.apache.struts2.dispatcher.ng.InitOperations.cleanup(InitOperations.java:114) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:60)
...continues for quite a while.

java.lang.NoClassDefFoundError: com/opensymphony/xwork2/ActionContext at org.apache.struts2.dispatcher.ng.InitOperations.cleanup(InitOperations.java:114) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init (StrutsPrepareAndExecuteFilter.java:60)
...持续了一段时间。

I have the Jar files downloaded from the Struts webpage and the way I went about setting to the build path is as follows:

我从 Struts 网页下载了 Jar 文件,我设置构建路径的方式如下:

I right clicked on the project and went to properties

我右键单击该项目并转到属性

Went to the Java Build Path section and created a new library

转到 Java Build Path 部分并创建了一个新库

Added all of the Jar files to that library and assigned it to this web application's build path

将所有 Jar 文件添加到该库并将其分配给此 Web 应用程序的构建路径

I then added this Jar library to the Deployment Assembly so that when it runs it gets deployed to the WEB-INF/lib folder.

然后我将此 Jar 库添加到部署程序集,以便在它运行时将其部署到 WEB-INF/lib 文件夹中。

As far as I know this should work, as it works in the tutorial I have followed! However, it is not working for me.

据我所知这应该有效,因为它在我遵循的教程中有效!但是,它对我不起作用。

When I run my project and navigate through my PC to where the project is saved, if I look in the WEB-INF/lib folder, there is no Jar files in there whatsoever, could this be where the problem lies? Or is this normal?

当我运行我的项目并通过我的 PC 导航到保存项目的位置时,如果我查看 WEB-INF/lib 文件夹,那里没有任何 Jar 文件,这可能是问题所在吗?或者这是正常的吗?

Thank you for any help, It's much appreciated!

感谢您的任何帮助,非常感谢!

EDIT

编辑

Here are the jar files I am using:

这是我正在使用的 jar 文件:

commons-fileupload-1.2.2
commons-io-2.0.1
commons-logging-1.1.1
commons-logging-api-1.1
freemarker-2.3.19
javaassist-3.11.0.GA
ognl-3.0.6
struts2-core-2.3.8
xwork-core-2.3.8
commons-lang-2.4

SOLVED - Solved by completely restarting the project on a fresh build! UPDATE - Also fixed old build by removing all jars and recreating the jar library, and reassigning it to the build path/Deplyment Assembly (Did this hundreds of times whilst trying to debug, though)

已解决 - 通过在全新构建中完全重新启动项目来解决!更新 - 还通过删除所有 jar 并重新创建 jar 库来修复旧构建,并将其重新分配给构建路径/部署程序集(尽管在尝试调试时做了数百次)

Then removed the old Tomcat server and assigned a new one.

然后删除旧的Tomcat服务器并分配一个新的。

Not entirely sure what fixed it, but it's all working, for now

不完全确定是什么修复了它,但现在一切正常

回答by Arvind

If you open the Markers viewthere should be a Classpath Dependency Validator Message warning group. If you expand that group you should see some warnings similar to:

如果您打开Markers 视图,应该有一个Classpath Dependency Validator Message 警告组。如果您展开该组,您应该会看到一些类似于以下内容的警告:

Classpath entry ??? will not be exported or published. RuntimeClassNotFoundExceptions may result.

类路径条目???不会被导出或发布可能会导致 RuntimeClassNotFoundExceptions。

Right click on these warnings and select Quick Fix. This allows you to mark the classpath entryfor inclusion in WEB-INF/lib.

右键单击这些警告并选择Quick Fix。这允许您标记类路径条目以包含在 WEB-INF/lib 中。