struts全包导入问题
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;
}
问题:
异常:
解决方法:
即,必须添加
struts-default.xml(必须),struts-plugin.xml(可选)二个额外的配置文件.
原因:
struts-default.xml是默认配置文件,一些必须的框架参数都默认设置在此.
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全包导入问题的更多相关文章
- struts导包
我用的是struts-2.2.3,开始把全部的jar包都放进去了,可是一直报 信息: Parsing configuration file [struts-plugin.xml]2011-6-11 8 ...
- python 包导入规则
python 包导入规则,恶心了一天,终于搞清楚了 1.目录 speed data __init__.py __init__.py static templates view __init__.py ...
- 解决 com.sun.*包导入错误
解决 com.sun.*包导入错误 com.sun.image.codec.jpeg.*导入错误如何解决: com.sun.*是受限制访问的API,Eclipse 默认把受访问限制的API设成了ERR ...
- 引入工程报包导入异常:import javax.servlet.annotation.WebFilter;
引入工程报包导入异常:import javax.servlet.annotation.WebFilter; (2013-02-21 16:38:00) 分类: java 今天上午导入了一个项目,用 ...
- 第三方jar包导入unity
关于第三方SDK接入Unity工程方面,有许多坑,下面我把遇到的问题进行总结,希望能够帮到有需要的朋友们.1.把第三方SDK导入Eclipse遇到的问题.eclipse配置完成右键工程后没有andro ...
- python包导入细节
包导入格式 导入模块时除了使用模块名进行导入,还可以使用目录名进行导入.例如,在sys.path路径下,有一个dir1/dir2/mod.py模块,那么在任意位置处都可以使用下面这种方式导入这个模块. ...
- jar包导入导出
java项目: 在classLoader加载jar和class的时候,是分开加载的,一般jar导入分两种: 1.在web-inf下的lib中直接引入 2.在user library上引入 无论以上哪种 ...
- Python 学习 第十五篇:模块搜索路径和包导入
在导入自定义的模块时,除了指定模块名之外,也需要指定目录,由于Python把目录称作包,因此,这类导入被称为包导入.包导入把计算机上的目录变成Python的命名空间,而目录中所包含的子目录和模块文件则 ...
- 【转】python包导入细节
[转]python包导入细节 包导入格式 导入模块时除了使用模块名进行导入,还可以使用目录名进行导入.例如,在sys.path路径下,有一个dir1/dir2/mod.py模块,那么在任意位置处都可以 ...
随机推荐
- APUE学习笔记——5.2流与文件对象、fwide
1 流 当一个文件被打开时,可以获得文件描述符.通过文件描述符可以对文件进行I/O操作.而I/O操作是通过流完成的. 流的定向: 在Unix系统中,使用 ASCII标准 ...
- (转) MapReduce Design Patterns(chapter 5 (part 1))(九)
Chapter 5. Join Patterns 把数据保存成一个巨大的数据集不是很常见.例如,用户信息数据频繁更新,所以要保存到关系数据库中.于此同时,web日志以恒定的数据流量增加,直接写到HDF ...
- d3.js(v5.7)的比例尺以及坐标轴
直接上代码了,这里的一些函数用的是之前我自己封装的函数(包括attr的obj支持和节点数量和数据数量的自动匹配),若有不明白的,可以查看之前的博客: 页面的效果如下: 接下来继续添加坐标轴: 最终:
- 地图API的选择和使用
在我们程序员的日常开发中,总会时不时的需要用到地图开发,我也在多次碰到之后,写下我对地图开发的理解经验和总结. 一.地图的选择 回想一下我们生活中用到的地图工具,数了一下,百度地图,高德地图,腾讯地图 ...
- jQuery AJAX 与 jQuery 事件
jQuery 本身即是为事件处理而特别设计的,jQuery 事件处理方法是 jQuery 中的核心函数. $(function() { ... }); 是如下格式的缩写: $(document).re ...
- artDialog的使用
用法一:github上下载包:https://github.com/aui/artDialog seajs方法使用 <!doctype html> <h ...
- nodejs返回接口给前端
1.修改app.js文件,将其中的user路由去掉. 2.在index路由中配置如下: router.all('*', function(req, res, next) { res.header( ...
- Git详解之五 分布式Git
以下内容转载自:http://www.open-open.com/lib/view/open1328070090108.html 分布式 Git 为了便于项目中的所有开发者分享代码,我们准备好了一台服 ...
- SaltStack简明教程
第1章 SaltStack简明教程 1.1 SaltStack简介 SaltStack是基于Python开发的一套C/S架构配置管理工具(功能不仅仅是配置管理,如使用salt-cloud配置AWS E ...
- jquery动态增加或删除tr和td【实际项目】
难点: (1)动态增加.删除tr和td (2)每天tr和td都有下标,且下标要动态变化, (3)tr和td为什么下标不能随便写,原因是此处需要把所有tr中的数据以list的形式发送到后台对象中,所有每 ...