2012-12-31 42 views
1

我想向我的struts.xml添加動作,但是當我這樣做時,我的webapp停止工作,我不知道爲什麼。我在這裏發佈我的web應用程序的一些細節。Struts 2向struts.xml添加一個動作

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> 

如果你需要一些額外的信息問我,但我想你可以看到爲什麼我的應用程序不想工作:/我敢肯定,這只是一個小錯誤,但我找不到它。 ..

感謝所有,並有一個快樂的新年晚會:)

(對不起,我的英語我是一個法國學生^^)

編輯:我張貼在這裏Eclipse的堆棧跟蹤其中告訴我,他找不到我的動作班,但我不知道爲什麼:/我有一個由我的老師做的struts示例,我不認爲他做了一些額外的步驟部署一個Tomcat服務器的應用程序基於Eclipse

堆棧跟蹤:

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

的網址是什麼,你輸入? – Suranga

+0

這只是'http:// localhost:8080:ILIMobileLeborgne /'應用程序的基礎url,當我刪除我的評論下的最後一個操作時,我的應用程序工作正常,如果我取消註釋,則無法訪問我的任何部分應用程序,我的瀏覽器總是說資源不可用:/ – BlackMario

+0

試試這個,localhost:8080/ILIMobileLeborgne/registerClientInfo – Suranga

回答

1

所以,聽起來像你的應用程序無法啓動,當你添加該動作,是否正確?什麼都行不通,即使是那些以前工作過的。所以,你應該查看你正在使用的servlet容器的日誌。沒有什麼比找到原木在哪裏並熟悉它們更重要的了。

當你看在日誌中,我猜你會看到無論是

1)錯誤抱怨struts.xml中的語法不好,試圖解析它,當應用程序失敗。

2)一個ClassNotFoundException因爲該動作的類文件不在應用程序的類路徑。如果是這種情況,請確保該操作的類文件實際上被放入WAR文件的WEB-INF/lib或WEB-INF/classes direcgtory;這是webapp的類加載器查找類文件的地方。如果你對此不太瞭解,你應該閱讀更多關於Java Servlets的信息。

這些都是可能導致應用程序無法成功啓動的事情。你必須看看日誌;他們會一直告訴你,應用程序有一個特定的問題。如果你在這個論壇上詢問有關特定問題,你會得到非常有用的答案。否則,我有點猜測。

+0

我看着日誌,我看到我的行動類SubscribeAction沒有找到!所以網絡無法正常啓動,但我不知道如何解決這個問題,我跟隨了一些關於struts網站的教程,他們用螞蟻來編譯類,但我不知道它是否是必需的,或者我們是否可以製作沒有它的應用程序:/(因爲這是一個研究項目,我不允許使用這種工具) – BlackMario

+0

我在編輯答案添加更多的參考,但它聽起來像你需要研究一些Java和java servlet的基礎知識。 – chad

+0

此外,由於我正確診斷你的問題,你可能會考慮接受答案:) – chad

0

默認.action擴展用於由您擴展struts-default包。當您將url放入瀏覽器時,請確保您使用的是正確的url

+0

我也嘗試過使用.action擴展名,因爲我不修改它,但它根本不起作用,添加與類SubscribeAction崩潰我的應用程序的操作,我無法訪問我的應用程序的任何部分:/也許我可以給你發一個.war,這樣你就可以自己看到問題了嗎?解釋問題可能更有效率,而不是一些句子:/ – BlackMario

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

爲什麼? SubscribeAction包含在操作包中。 – chad

相關問題