1

我想向我添加一个动作,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>

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

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>

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

谢谢大家,祝大家新年快乐:)

(对不起我的英语我是法国学生^^)

编辑:我在这里发布了 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
4

3 回答 3

1

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

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

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

或者

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

这两种情况都可能导致应用程序无法成功启动。您必须查看日志;他们几乎总是会告诉您该应用程序存在特定问题。如果您在此论坛上询问该特定问题,您将得到非常有用的答案。否则,我有点猜测。

于 2012-12-31T21:01:38.920 回答
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>
于 2013-01-03T15:06:59.520 回答
0

默认情况下,.action扩展由struts-default您扩展的包使用。当您将url放在浏览器中时,请确保您使用了正确的url.

于 2012-12-31T19:20:36.847 回答