Accès aux ressources par l'interface SessionAware
bonjour,
j'essaye de faire fonctionner mon programme de saisie de l'identifiant et du mot de passe, mais j'ai ce message d'erreur:
Citation:
Etat HTTP 404 -
--------------------------------------------------------------------------------
type Rapport d'état
message
description La ressource demandée () n'est pas disponible.
Voici le fichier struts.xml:
Code:
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
| <?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="true" />
<package name="exemple03" namespace="/" extends="struts-default">
<default-action-ref name="Ajouter_Client" />
<action name="Ajouter_Client">
<result>/jsp/AjouterClient.jsp</result>
</action>
<action name="ValiderAjouter_Client"
class="exemple03.Client" method="ajouter">
<result name="input">/jsp/AjouterClient.jsp</result>
<result name="success">/jsp/AfficherClient.jsp</result>
</action>
<action name="Supprimer_Client" class="exemple03.Client" method="supprimer">
<result name="success">/jsp/AfficherClient.jsp</result>
</action>
</package>
</struts> |
Voici le fichier AjouterClient.jsp:
Code:
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
| <html>
<head>
<title>Ajouter un client </title>
<style type="text/css">@import url(css/styles.css);</style>
</head>
<body>
<div id="enveloppe">
<h3>Ajouter un client</h3>
<form method="post" action="ValiderAjouter_Client.action">
<table>
<tr>
<td>Identifiant:</td>
<td><input type="text" name="identifiant" value="${identifiant}"/></td>
</tr>
<tr>
<td>Mot de passe:</td>
<td><input type="text" name="motdepasse" value="${motdepasse}"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Ajouter le client"/></td>
</tr>
</table>
</form>
</div>
</body>
</html> |
Voici le fichier AfficherClient.jsp:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Afficher le client</title>
<style type="text/css">@import url(css/styles.css);</style>
</head>
<body>
<s:debug/>
<div id="enveloppe">
<p>
<h4>Informations sur le client:</h4>
Identifiant : <s:property value="#session.identifiantsession"/><br/>
Mot de passe : <s:property value="#session.motdepassesession"/><br/>
</p>
<a href="Supprimer_Client.action">Supprimer le client</a>
</div>
</body>
</html> |
Voici le fichier Client.java:
Code:
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 44 45 46 47 48 49 50 51 52
| package example03;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
@SuppressWarnings("serial")
public class Client extends ActionSupport implements SessionAware {
private Map<Object, Object> session;
private Object someObjectFromSession;
private String identifiant;
private String motdepasse;
public String getIdentifiant() {
return identifiant;
}
public void setIdentifiant(String identifiant) {
this.identifiant = identifiant;
}
public String getMotdepasse() {
return motdepasse;
}
public void setMotdepasse(String motdepasse) {
this.motdepasse = motdepasse;
}
public String ajouter() {
someObjectFromSession = session.put("identifiantsession", identifiant);
someObjectFromSession = session.put("motdepassesession", motdepasse);
System.out.println(session.get("identificationsession"));
return SUCCESS;
}
public String supprimer() {
someObjectFromSession = session.remove("identifiantsession");
someObjectFromSession = session.remove("motdepassesession");
System.out.println(session.get("identificationsession"));
return SUCCESS;
}
@Override
public void setSession(Map session) {
this.session = session;
}
} |
J'avoue que je ne sais pas trop comment créer le fichier Client.java, je suppose que les problèmes viennent de là. Notamment, comment récupérer les valeurs des attributs de la requête lancé par l'action ValiderAjouter_Client.action.
J'essaye de tester l'application par: http://localhost/exemple03/Ajouter_Client.action
Merci d'avance pour votre aide.
Mumu27