真心是跪求,搞了一晚上了,都没搞定,关于struts2

lipei123l 2015-07-09 03:10:04
我实在是无法了.实在搞不懂我到底哪里错了.难道是书有问题?

这是我的struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<package name="mypackage" namespace="/" extends="struts-default">
<action name="u" class="action.user">
<result name="a">a.jsp</result>
<result name="d">b.jsp</result>
</action>
</package>
</struts>


这是我的index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'index.jsp' starting page</title>
</head>

<body>
<a href="u!add">a</a>
<a href="u!del">b</a>
</body>
</html>



这是我的user,是一个继承actionsupport的类
package action;

import com.opensymphony.xwork2.ActionSupport;


public class user extends ActionSupport {

/**
*
*/
private static final long serialVersionUID = 1L;
private String l="hi";
public String add() throws Exception{
l="1";
return "a";
}
public String del() throws Exception{
l="2";
return "d";
}
public String getL() {
return l;
}
public void setL(String l) {
this.l = l;
}

}


这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

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



</web-app>


剩下的a.jsp,b.jsp都是无所谓的显示结果的页面,最重要的是这个,一旦部署就报这个错,但是这个uesrAction在哪啊!?
严重: Exception starting filter struts2
java.lang.NoClassDefFoundError: IllegalName: /struts.userAction
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:655)
at java.lang.ClassLoader.defineClass(ClassLoader.java:794)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2472)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:854)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1274)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
at com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:144)
at com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:135)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:476)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:429)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:556)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4573)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5192)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1096)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1756)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

跪求大神们
...全文
158 1 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zhanganbo 2015-07-09
你为啥result 里面的a.jsp 和 b.jsp不带“/” 例如:/a.jsp ,/b.jsp
回复
lipei123l 2015-07-09
引用 3 楼 xuyanzhuo 的回复:
修改struts.xml配置文件如下。直接拷贝覆盖。 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- 动态方法--> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <!--将此常量设置为true,这种方式才能使用动态方法--> <package name="mypackage" namespace="/" extends="struts-default"> <action name="u" class="action.user"> <result name="a">a.jsp</result> <result name="d">b.jsp</result> </action> </package> </struts>
十分感谢~!!!
回复
xiaohuashenshou 2015-07-09
3楼正解,user!add.action这样的调用方式属于dynamic method invoke(动态方法调用),好像在struts2.3.15之后的版本,你可以在你的struts的jar包中找到一个default.properties文件,这个文件里的struts.enable.DynamicMethodInvocation=false,和以前的不一样,你可以在struts.xml文件中重新设置一下就好了
回复
xuyanzhuo 2015-07-09
修改struts.xml配置文件如下。直接拷贝覆盖。 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- 动态方法--> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <!--将此常量设置为true,这种方式才能使用动态方法--> <package name="mypackage" namespace="/" extends="struts-default"> <action name="u" class="action.user"> <result name="a">a.jsp</result> <result name="d">b.jsp</result> </action> </package> </struts>
回复
lipei123l 2015-07-09
引用 1 楼 yuxiang_lyp 的回复:
<a href="u!add">a</a>改成<a href="u!add.action">a</a>试试
一样的,我觉得是不是报错那少了什么包?
回复
夜灵_雪 2015-07-09
<a href="u!add">a</a>改成<a href="u!add.action">a</a>试试
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-07-09 03:10
社区公告
暂无公告