IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Struts 2 Java Discussion :

Erreur Struts 2 : There is no Action.


Sujet :

Struts 2 Java

  1. #1
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2008
    Messages
    197
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 197
    Points : 117
    Points
    117
    Par défaut Erreur Struts 2 : There is no Action.
    Salut,
    Je débute avec Struts 2 :
    j'ai fait un exemple en se basant sur un toturial du net.
    Voici le code struts.xml:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <?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.enable.DynamicMethodInvocation" value="false" />
    	<constant name="struts.devMode" value="false" />
    	<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
     
     
    	<package name="default" extends="struts-default" namespace="/">
     
    		<action name="login" class="com.struts.Action.LoginAction" >
    			<result name="success">Welcome.jsp</result>
    			<result name="error">Login.jsp</result>
    		</action>
    	</package>
    </struts>
    Mon web.xml :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" 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">
    	<display-name>ExempleStruts</display-name>
     
     
    	<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>Login.jsp</welcome-file>
    	</welcome-file-list>
    </web-app>
    La page login.jsp :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <%@ page contentType="text/html; charset=UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <html>
    <head>
    <title>Struts 2 - Login Application | ViralPatel.net</title>
    </head>
     
    <body>
    <h2>Struts 2 - Login Application</h2>
    <s:actionerror />
    <s:form action="login.action" method="post">
    	<s:textfield name="username" key="label.username" size="20" />
    	<s:password name="password" key="label.password" size="20" />
    	<s:submit method="execute" key="label.login" align="center" />
    </s:form>
    </body>
    </html>
    la class LoginAction.java :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    package com.struts.Action;
     
    import java.util.Map;
     
    import org.apache.struts2.interceptor.PrincipalAware;
    import org.apache.struts2.interceptor.PrincipalProxy;
    import org.apache.struts2.interceptor.SessionAware;
     
    import com.opensymphony.xwork2.ActionSupport;
    import com.opensymphony.xwork2.Preparable;
     
    public class LoginAction extends ActionSupport  {
    	private String username;
    	private String password;
     
    	public String execute() {
     
    		if (this.username.equals("admin") && this.password.equals("admin123")) {
    			return "success";
    		} else {
    			addActionError(getText("error.login"));
    			return "error";
    		}
    	}
     
    	public String getUsername() {
    		return username;
    	}
     
    	public void setUsername(String username) {
    		this.username = username;
    	}
     
    	public String getPassword() {
    		return password;
    	}
     
    	public void setPassword(String password) {
    		this.password = password;
    	}
     
     
    }
    - Le fichier struts.xml se trouve sous le répertoire /ressources, et les pages jsp se trouve sous le fichier par défaut du projet /webContent.

    L'erreur suivante s'affiche dans le console :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    INFO: Server startup in 696 ms
    1 juin 2010 13:46:56 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
    ATTENTION: Could not find action or result
    There is no Action mapped for namespace / and action name login. - [unknown location]
    	at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
    	at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    	at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    	at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
    	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
    	at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	at java.lang.Thread.run(Unknown Source)

    C'est un problème de configuration, mais j'ai pas trouvé de solution tous parait juste.

    Et merci d'avance.

  2. #2
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 31
    Points : 36
    Points
    36
    Par défaut
    Il faut enlever le .action dans ton formulaire

    <s:form action="login" method="post">

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2008
    Messages
    197
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 197
    Points : 117
    Points
    117
    Par défaut
    Merci pour votre réponse,
    j'ai enlevé, la même erreur existe encore
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    There is no Action mapped for namespace / and action name login.

  4. #4
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2008
    Messages
    197
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 197
    Points : 117
    Points
    117
    Par défaut
    salut,

    J'ai arrivé à résoudre le problème :
    Il suffit de mettre le fichier struts.xml sous le répertoire /src où se trouve le package des actions.
    Ma faute c'est que j'ai déclarer struts.xml dans un répertoire ressources.

    Tous le reste c'est bon.

  5. #5
    Membre du Club Avatar de ilamine55
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 89
    Points : 48
    Points
    48
    Par défaut
    ce n est pas le même problème, mon fichier struts.xml est bien dans le dossier src .

  6. #6
    Nouveau Candidat au Club
    Inscrit en
    Janvier 2011
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 1
    Points : 1
    Points
    1
    Par défaut
    j'ai le même problème svp qui a une réponse

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur "There is no Action mapped "
    Par Death Noto dans le forum Struts 2
    Réponses: 6
    Dernier message: 12/04/2013, 18h32
  2. [struts]erreur 404:ne trouve pas l'action...
    Par questionneuse dans le forum Struts 1
    Réponses: 7
    Dernier message: 05/05/2006, 11h55
  3. Réponses: 4
    Dernier message: 02/09/2005, 15h40
  4. [Struts] question bete sur les Action et Form
    Par seb_fou dans le forum Struts 1
    Réponses: 2
    Dernier message: 06/09/2004, 16h24
  5. Réponses: 4
    Dernier message: 27/04/2004, 15h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo