Struts 2向struts.xml添加了一个动作

时间:2012-12-31 18:23:48

标签: java eclipse struts2

我想向我的struts.xml添加一个动作,但是当我这样做时,我的webapp停止工作,我不知道为什么。我在这里发布了我的webapp的一些细节。

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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>ILIMobileLeborgne</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

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

struts.xml(在Eclipse的src文件夹中):

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

<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="ilimobile" />

<package name="ilimobile" namespace="/" extends="struts-default">

    <action name="index">
        <result>/index.jsp</result>
    </action>

    <action name="registerIllimite">
        <result>/registerIllimite.jsp</result>
    </action>

      <!-- When i try to do add the following action my app doesn't working, the browser said me that the ressource asked is unavailable and when i delete it my (little) app works correctly -->
    <action name="registerClientInfo"  class="action.SubscribeAction">
        <result name="success">/paiement.jsp</result>
    </action>

</package>

</struts>

我的SubscribeAction(在源文件夹的操作包中):

package action;

import model.*;

import com.opensymphony.xwork2.ActionSupport;

public class SubscribeAction extends ActionSupport {
private Client client;
private String abonnement;

public String getAbonnement() {
    return abonnement;
}

public void setAbonnement(String abonnement) {
    this.abonnement = abonnement;
}

@Override
public String execute() throws Exception {
    // TODO Auto-generated method stub
    return SUCCESS;
}

public Client getClient() {
    return client;
}

public void setClient(Client client) {
    this.client = client;
}
}

我的JSP页面使用了定义的操作:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%> 
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Insert title here</title>
 </head>
 <body>
<s:form action="registerClientInfo">
    <s:textfield key="client.nom"/>
    <s:textfield key="client.prenom"/>
    <s:textfield key="client.email"/>
    <s:textfield key="client.adresse"/>
    <s:textfield key="client.ville"/>
    <s:textfield key="client.cp"/>

    <s:submit/>
</s:form>
 </body>
</html>

如果你需要一些额外的信息问我,但我想你可以看到为什么我的应用程序不想工作:/我很确定它只是一个小错误但我找不到它...... / p>

感谢所有人,并祝新年快乐派对:)

(抱歉我的英语我是法国学生^^)

编辑:我在这里发布Eclipse堆栈跟踪,告诉我他找不到我的动作类,但我不知道为什么:/我有一个由我的老师做的struts示例,我不认为他做了一些额外的步骤,在Eclipse上用tomcat服务器部署应用程序

堆栈跟踪:

Unable to load configuration. - action - file:/home/blackmario/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ILIMobileLeborgne/WEB-INF/classes/struts.xml:20:68
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:429)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:471)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)


Caused by: Action class [action.SubscribeAction] not found - action - file:/home/blackmario/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ILIMobileLeborgne/WEB-INF/classes/struts.xml:20:68
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:480)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:424)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:541)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:290)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:239)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
    ... 18 more

3 个答案:

答案 0 :(得分:1)

因此,当您添加该操作时,听起来您的应用程序无法启动,对吗?没有任何作用,即使是之前有效的。因此,您应该查看正在使用的servlet容器的日志。找到日志的位置并熟悉它们,没有比这更重要的了。

当你查看日志时,我猜你会看到

1)一个错误,抱怨struts.xml的语法错误,并且在尝试解析时应用程序失败。

2)ClassNotFoundException,因为该操作的类文件不在应用程序的类路径上。如果是这种情况,请确保该操作的类文件实际上被放入WAR文件的WEB-INF / lib或WEB-INF / classes direcgtory中;这就是webapp的类加载器查找类文件的地方。如果您对此不太了解,请阅读有关Java Servlets的更多信息。

这些都可能导致应用程序无法成功启动。你必须看看日志;他们会告诉你应用程序有一个特定的问题。如果您在此论坛上询问该特定问题,您将获得非常有用的答案。否则,我有点猜测。

答案 1 :(得分:0)

默认.action扩展程序由您扩展的struts-default包使用。将url放入浏览器时,请确保使用正确的url

答案 2 :(得分:0)

尝试更改

<action name="registerClientInfo"  class="action.SubscribeAction">
    <result name="success">/paiement.jsp</result>
</action>

<action name="registerClientInfo"  class="SubscribeAction">
    <result name="success">/paiement.jsp</result>
</action>