page d'authentification d'une application Struts
Salut la liste,
J'ai une application qui a 3 pages jsp: login.jsp, failure.jsp et success.jsp.
login.jsp est la page d'accueil de l'application, en cas d'authenfication correcte success.jsp est affiché, dans le cas contraire c'est failure.jsp.
login.jsp
failure.jsp
success.jsp
A l'éxécution, la page login.jsp s'affiche correctement seulement lorsqu'on se connecte, j'ai l'erreur 404, je ne comprends pourquoi ?
le fichier struts-config.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 26 27 28 29 30 31 32 33
| <?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
<struts-config>
<!-- =================== Configuration des beans ==================================== -->
<form-beans>
<form-bean name="LoginForm" type="com.serli.login.action.LoginForm">
</form-bean>
</form-beans>
<!-- =================== Configuration des mappings ==================================== -->
<action-mappings>
<action
path="/login"
type="com.serli.login.action.LoginAction"
name="LoginForm"
scope="request"
validate="true"
input="/pages/login.jsp">
<forward name="success" path="/pages/success.jsp"/>
<forward name="failure" path="/pages/failure.jsp"/>
</action>
</action-mappings>
<!-- =========================== Ressources de définition de messages ============= -->
<message-resources parameter="Resources" />
</struts-config> |
le fichier web.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
| <?xml version="1.0" ?>
<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>com.serli.login</display-name>
<!-- ========================== Page d'accueil =========================================== -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<!-- ========================== Configuration de l'action servlet ========================= -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app> |
La classe LoginAction
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
|
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LoginAction extends Action {
public ActionForward execute ( ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
LoginForm loginform = (LoginForm) form;
if (loginform.getUsername().equalsIgnoreCase("username") && loginform.getPassword().equals("password")) {
// we are in
return mapping.findForward("success");
} else {
// not allowed
return mapping.findForward("failure");
}
}
} |
La classe LoginForm
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 53 54
| import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
public class LoginForm extends ActionForm
{
/**
*
*/
private static final long serialVersionUID = 1L;
private String action="add";
private String username=null;
private String password=null;
private String usertype=null;
public void setAction(String action){
this.action=action;
}
public String getAction(){
return this.action;
}
public void setUsername(String username){
this.username=username;
}
public String getUsername(){
return this.username;
}
public void setPassword(String password){
this.password=password;
}
public String getPassword(){
return this.password;
}
public void setUsertype(String usertype){
this.usertype=usertype;
}
public String getUsertype(){
return this.usertype;
}
public void reset(ActionMapping mapping,HttpServletRequest request){
this.username=null;
this.password=null;
this.usertype=null;
this.action="add";
} |
Quelqu'un aurait une idée ?
Merci beaucoup d'avance.