lecture d'un formulaire avec struts2
Salut tout le monde. J'ai un formulaire d'authentification que je dois recuperer dans mon application afin de faire le test.
Le probleme que j'ai c'est que lors du test dans ma classe login.java, les champs récupéré sont à null. Deja au demarrage de mon appli j'ai un warning bizzare qui dit:
ATTENTION: No configuration found for the specified action: '/authentification/dologin.action' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
Voila mes fichiers:
web.xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <?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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>sugar-report</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>index.jsp</welcome-file>
</welcome-file-list>
</web-app> |
struts.xml:
Code:
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.devMode" value="false" />
<constant name="struts.i18n.reload" value="false" />
<constant name="struts.configuration.xml.reload" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<package name="authentification" namespace="/authentification" extends="struts-default">
<action name="dologin" class="ma.involys.service.login">
<result name="input">/index.jsp</result>
<result name="SUCCESS">/accueil.jsp</result>
<result name="ERROR">/accueil.jsp</result>
<result>/index.jsp</result>
</action>
</package> |
login.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
| import com.opensymphony.xwork2.ActionSupport;
public class login extends ActionSupport{
public String execute() throws Exception {
System.out.println("Validating login");
System.out.println(getutil());
if(!getutil().equals("admin") || !getpass().equals("admin")){
addActionError("Invalid user name or password! Please try again!");
System.out.println("error");
return ERROR;
}else{
System.out.println("success");
return SUCCESS;
}
}
private String util = null;
public String getutil() {
return util; }
public void setutil(String value) {
util = value; }
private String pass = null;
public String getpass() {
return pass; }
public void setpass(String value) {
pass = value; }
} |
index.jsp:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <s:form action="/authentification/dologin.action">
<center>
<table>
<tr>
<td><s:textfield label="Utilisateur" name="util" /></td>
</tr>
<tr>
<td><s:password label="Mot de passe" name="pass" /></td>
</tr>
<tr>
<td><s:submit value="Se connecter" /></td>
</tr>
</table>
</center>
</s:form> |
Je flippe depuis une semaine là dessus, s'il vous plait si quelqu'un peut me filer un petit coup de main pour ne pas dire un coup de pied :( je lui serais très reconnaissant :ccool: