[STRUTS] Actions et forms
Bonjour j ai une question en rapport avec le framework struts. A noter que j utiise les tiles.
Voila je voudais sur ma page /index.do, afficher un nombre (un nombre de personnes connectées sur le site par exemple).
Ce nombre est recupere a partir d une source externe (fichier par exemple).
Pour ce faire je "mappe" une page init.do avec une action nommee IndexAction. Cette action est liee a un formulaire nomme IndexForm.
En voici le code (c est un test!!)
IndexForm
--------------
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
|
public final class IndexForm extends ActionForm{
//Connection number
private int connectionNumber = 0;
/**
* Reset all properties to their default values.
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
this.setConnectionNumber(0);
}
/**
* @return Returns the connectionNumber.
*/
public int getConnectionNumber() {
return connectionNumber;
}
/**
* @param connectionNumber The connectionNumber to set.
*/
public void setConnectionNumber(int connectionNumber) {
this.connectionNumber = connectionNumber;
}
} |
IndexAction
--------------
Code:
1 2 3 4 5 6 7 8 9
|
public ActionForward execute(
ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
((IndexForm)form).setConnectionNumber(10);
return mapping.findForward("success");
} |
L action met juste a jour les connections avec la valeur 10
Le struts-config
------------------
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
|
<!-- Form beans definition -->
<form-beans>
<form-bean
name="IndexForm"
type="org.semperefamily.forms.IndexForm"/>
</form-beans>
<!-- Global forward definitions -->
<global-forwards>
<forward name="home" path="/index.do"/>
<forward name="resources" path="/resources.do"/>
<forward name="informations" path="/informations.do"/>
<forward name="realisations" path="/realisations"/>
</global-forwards>
<!-- Action Mappings Configuration -->
<action-mappings>
<action path="/init"
type="org.semperefamily.actions.IndexAction"
name="IndexForm"
validate="false">
<forward name="failure" path="/resources.do"/>
<forward name="success" path="index.layout"/>
</action>
<action path="/index"
type="org.apache.struts.actions.ForwardAction"
parameter="index.layout"/> |
Normalement lorsque la page /init.do est demandee, IndexAction va mettre le champs connectionNumber de l IndexForm a 10 et va faire un forward vers la page /index.do
Ma question est: Que dois je ecrire dans la jsp liee a /index.do pour que la valeur 'connectionNumber' de IndexForm soit affichee???
Merci, je n y arrive pas 8O