web.xml如下: 
<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
<display-name>SS</display-name>

<listener> 
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener>

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

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

<welcome-file-list> 
<welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 
</web-app>

在WEB-INF下新建applicationContext.xml: 
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 
<beans>

</beans>

src下新建struts.xml: 
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC "//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
<package name="default" namespace="/" extends="struts-default"> 
<action name="HelloWorld" class="com.ghl.HelloWorld"> 
<result name="success">/success.jsp</result> 
</action> 
</package> 
<include file="user.xml"></include> 
</struts>

src下新建com.ghl.HelloWorld.java: 
package com.ghl;

import com.opensymphony.xwork2.ActionSupport; 
import com.opensymphony.xwork2.util.logging.Logger; 
import com.opensymphony.xwork2.util.logging.LoggerFactory;

public class HelloWorld extends ActionSupport{ 
/** 

*/ 
private static final long serialVersionUID = -6452565149473931988L; 
Logger log = LoggerFactory.getLogger(HelloWorld.class);

@Override 
public String execute() throws Exception { 
log.info("execute"); 
return SUCCESS; 
}

@Override 
public void validate() { 
log.info("validate"); 

}

部署在tomcat下,问题: 
警告: Unable to load config class org.apache.struts2.jsf.FacesSetupInterceptor at interceptor - jar:file:/D:/ghl/apache-tomcat-6.0.20/wtpwebapps/SS/WEB-INF/lib/struts2-jsf-plugin-2.1.8.1.jar!/struts-plugin.xml:35:97 probably due to a missing jar, which might be fine if you never plan to use the jsfSetup interceptor 
2010-6-10 14:14:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error 
严重: Actual exception 
Could not load class org.apache.struts2.jsf.FacesSetupInterceptor. Perhaps it exists but certain dependencies are not available? - interceptor - jar:file:/D:/ghl/apache-tomcat-6.0.20/wtpwebapps/SS/WEB-INF/lib/struts2-jsf-plugin-2.1.8.1.jar!/struts-plugin.xml:35:97 
at com.opensymphony.xwork2.ObjectFactory.buildInterceptor(ObjectFactory.java:202)

解决: 
删除:struts2-jsf-plugin-2.1.8.1.jar

问题: 
警告: Unable to load config class org.apache.struts2.portlet.interceptor.PortletAwareInterceptor at interceptor - jar:file:/D:/ghl/apache-tomcat-6.0.20/wtpwebapps/SS/WEB-INF/lib/struts2-portlet-plugin-2.1.8.1.jar!/struts-plugin.xml:48:114 probably due to a missing jar, which might be fine if you never plan to use the portletAware interceptor 
2010-6-10 14:16:37 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error 
严重: Actual exception 
Could not load class org.apache.struts2.portlet.interceptor.PortletAwareInterceptor. Perhaps it exists but certain dependencies are not available? - interceptor - jar:file:/D:/ghl/apache-tomcat-6.0.20/wtpwebapps/SS/WEB-INF/lib/struts2-portlet-plugin-2.1.8.1.jar!/struts-plugin.xml:48:114 
at com.opensymphony.xwork2.ObjectFactory.buildInterceptor(ObjectFactory.java:202)

解决 
删除:struts2-portlet-plugin-2.1.8.1.jar

问题: 
严重: Dispatcher initialization failed 
java.lang.NullPointerException 
at org.apache.struts2.osgi.OsgiConfigurationProvider.init(OsgiConfigurationProvider.java:70) 
解决: 
删除:struts2-osgi-plugin-2.1.8.1.jar

问题: 
严重: Dispatcher initialization failed 
java.lang.RuntimeException: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String). 
at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:132) 
解决: 
修改web.xml: 
<filter> 
<filter-name>struts2</filter-name> 
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
      <init-param> 
<param-name>actionPackages</param-name> 
<param-value>com.ghl</param-value> 
</init-param> 
</filter>

问题: 
警告: Could not find action or result 
There is no Action mapped for namespace / and action name HelloWorld. - [unknown location] 
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178) 
解决: 
把 struts.xml文件放到WEB-INF/classes目录下

问题: 
java.lang.NoSuchMethodException: com.ghl.HelloWorld.index() 
java.lang.Class.getMethod(Unknown Source) 
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
解决: 
HelloWorld.java中追加方法: 
public String index(){ 
log.info("index"); 
return SUCCESS; 
}

问题:

异常:

com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory). - Class: com.opensymphony.xwork2.inject.ContainerImpl File: ContainerImpl.java
解决方法:

  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      <init-param>  
        <param-name>config</param-name>  
        <param-value>struts-default.xml,struts-plugin.xml,struts2/struts-*.xml</param-value>  
    </init-param>  
 </filter>
即,必须添加

 

struts-default.xml(必须),struts-plugin.xml(可选)二个额外的配置文件.
原因:
struts-default.xml是默认配置文件,一些必须的框架参数都默认设置在此.

 
 
 
问题:
nable to load configuration. - package - file:/c:/clients/PSWD/eclipse/msc_workspace/PSWDBase/WebContent/WEB-INF/classes/struts.xml:14:71 
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58) 
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360) 
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403) 
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
</package>
<!-- Add packages here -->
<!-- 测试界面 -->
<include file="cn/com/test/action/struts-admin-action.xml" />
</struts>

将上面的default改成test。

问题:

遇到一个Jetty tmp的陷阱

今天碰到一个古怪的问题,运行在Jetty服务器下的一个系统,忽然爆出一个“404,页面找不到”的错误,重启系统后问题就解决。之前也碰到一个类似的问题,当时也是重启后搞定,上次事件后,查找了一下原因,没有结果,这事情也就放下了。这次再次出现同样的问题,感觉问题比较严重,必须解决这个隐患了。

出现这个问题后,到服务器上看了一下,发现这个Jetty的进程还在,同样运行的其它几个服务也都正常。分析Jetty和应用日志后,也没有发现异常情况。再次回头看一下,抛出的错误信息:

HTTP ERROR 404

Problem accessing /pages/index.jsp. Reason:

Not Found

这个错误显示是index.jsp这个文件访问不到了。于是到Jetty部署解决war的默认目录/tmp去查看,这时其实已经于事无补了,因为刚才重启过,之前目录中的文件全部会被覆盖。

初步怀疑是war解压出的文件被删除了,问了一下SA有没有cron任务在晚上运行,会不会影响/tmp目录的文件,结果他表示没有。于是继续查看Nginx日志,发现在3点36分钟时,前一个请求返回的是200,后一个就变成404了。这时另外一个同事提醒说,系统默认的tmpwatch任务会清除/tmp目录下的文件。如下:

cat /etc/cron.daily/tmpwatch
#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch “$flags” -x /tmp/.X11-unix -x /tmp/.XIM-unix \
-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
-X ‘/tmp/hsperfdata_*’ 10d /tmp
/usr/sbin/tmpwatch “$flags” 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch “$flags” -f 30d “$d”
fi
done

上面的脚本表示,tmpwatch分根据文件的修改(-m)/创建(-c)时间,清理/tmp下的10天前创建或修改的文件,问题就在这里了。如何解决呢?只要让Jetty解压war文件时,不放在/tmp下就能解决这个问题了。仔细查看Jetty的关于Temporary Directories 的描述文档,原来只需要在${jetty.home}目录下创建一个work目录就行了。Jetty的这个Trick害死人,为什么不在Jetty发布包中就默认包含这个目录呢?

教训:使用开源的东西,一定要认真读一下它的文档,对于比较关键的问题,一定要非常熟悉,否则出了问题才来想办法解决,已经晚了。

struts全包导入问题的更多相关文章

  1. struts导包

    我用的是struts-2.2.3,开始把全部的jar包都放进去了,可是一直报 信息: Parsing configuration file [struts-plugin.xml]2011-6-11 8 ...

  2. python 包导入规则

    python 包导入规则,恶心了一天,终于搞清楚了 1.目录 speed data __init__.py __init__.py static templates view __init__.py ...

  3. 解决 com.sun.*包导入错误

    解决 com.sun.*包导入错误 com.sun.image.codec.jpeg.*导入错误如何解决: com.sun.*是受限制访问的API,Eclipse 默认把受访问限制的API设成了ERR ...

  4. 引入工程报包导入异常:import javax.servlet.annotation.WebFilter;

    引入工程报包导入异常:import javax.servlet.annotation.WebFilter; (2013-02-21 16:38:00)   分类: java 今天上午导入了一个项目,用 ...

  5. 第三方jar包导入unity

    关于第三方SDK接入Unity工程方面,有许多坑,下面我把遇到的问题进行总结,希望能够帮到有需要的朋友们.1.把第三方SDK导入Eclipse遇到的问题.eclipse配置完成右键工程后没有andro ...

  6. python包导入细节

    包导入格式 导入模块时除了使用模块名进行导入,还可以使用目录名进行导入.例如,在sys.path路径下,有一个dir1/dir2/mod.py模块,那么在任意位置处都可以使用下面这种方式导入这个模块. ...

  7. jar包导入导出

    java项目: 在classLoader加载jar和class的时候,是分开加载的,一般jar导入分两种: 1.在web-inf下的lib中直接引入 2.在user library上引入 无论以上哪种 ...

  8. Python 学习 第十五篇:模块搜索路径和包导入

    在导入自定义的模块时,除了指定模块名之外,也需要指定目录,由于Python把目录称作包,因此,这类导入被称为包导入.包导入把计算机上的目录变成Python的命名空间,而目录中所包含的子目录和模块文件则 ...

  9. 【转】python包导入细节

    [转]python包导入细节 包导入格式 导入模块时除了使用模块名进行导入,还可以使用目录名进行导入.例如,在sys.path路径下,有一个dir1/dir2/mod.py模块,那么在任意位置处都可以 ...

随机推荐

  1. ClassPathXmlApplicationContext类

    org.springframework.context.support Class ClassPathXmlApplicationContext java.lang.Objectorg.springf ...

  2. 本地如何搭建IPv6环境测试你的APP(转)

    IPv6的简介 IPv4 和 IPv6的区别就是 IP 地址前者是 .(dot)分割,后者是以 :(冒号)分割的(更多详细信息自行搜索). PS:在使用 IPv6 的热点时候,记得手机开 飞行模式 哦 ...

  3. MoreEffectiveC++Item35(效率)(条款16-24)

    条款16 谨记80-20法则 条款17 考虑使用 lazy evaluation(缓释评估) 条款18 分期摊还预期的计算成本 条款19 了解临时对象的来源 条款20 协助完成"返回值的优化 ...

  4. 一个浮动 css3效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. c# http操作类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  6. about system (pause) in cpp

    Which is best way to pause the console in C++ programs? using cin.get() or using system("pause& ...

  7. 更换pip源,解决pip install安装包慢的问题

    而pip是很强大的Python包安装工具,但是由于国外官方pypi经常被墙,导致不可用,所以最好是将使用的pip源更换一下,这样就能解决被墙导致的装不上库的问题.网上有很多可用的源,例如豆瓣:http ...

  8. Shell 单行注释和多行注释

  9. 提问:错误提示--命名空间“System.Web”中不存在类型或命名空间名称“UI”(是缺少程序集引用吗?) 如何解决??

    转自:http://topic.csdn.net/u/20080723/21/7e1e06cb-d013-4675-ba9b-9b39d49d0a0e.html 1) 添加对System.Web.dl ...

  10. confd与etcd的使用

    Add keys This guide assumes you have a working etcd, or consul server up and running and the ability ...