[Struts 1.3.8] bloqué après l'action "do"
Bonjour,
Je débute en Struts et j'essaie de faire fontionner un pauvre formulaire en vue de créer un site (y'a encore du boulot...). Bref, j'ai l'impression que tout est correct mais quand je valide le formulaire, rien ne se passe, ça reste bloqué et la console indique :
Citation:
Initialize action of type: com.montana.occasion.actions.ActionInscription
Voici mon code :
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 25 26 27 28 29 30 31 32
| <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4">
<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>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
</taglib>
</jsp-config>
</web-app> |
struts-config.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="user" type="com.montana.occasion.bean.User"/>
</form-beans>
<action-mappings>
<action
path="/inscription"
type="com.montana.occasion.actions.ActionInscription"
validate="true"
name="user"
scope="session"
input="/inscription.jsp">
<forward name="success" path="/inscription_result.jsp"/>
</action>
</action-mappings>
</struts-config> |
com.montana.occasion.bean.User :
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
| package com.montana.occasion.bean;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class User extends ActionForm {
static final long serialVersionUID = 1L;
String nom, message;
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public ActionErrors validate (ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (nom.equals("")) {
errors.add("nom", new ActionMessage("Veuillez entrer un nom"));
}
return errors;
}
} |
com.montana.occasion.actions.ActionInscription :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| package com.montana.occasion.actions;
import java.io.IOException;
import javax.servlet.ServletException;
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;
import com.montana.occasion.bean.User;
public class ActionInscription extends Action {
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
User user = (User) form;
user.setMessage("Bonjour, " + user.getNom());
return (mapping.findForward("success"));
}
} |
inscription.jsp :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="WEB-INF/tld/struts-html.tld" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Inscription</title>
</head>
<body>
<html:form action="/inscription.do">
Nom : <html:text property="nom" size="20"/>
<html:submit>Valider</html:submit>
</html:form>
</body>
</html> |
inscription_result.jsp :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="WEB-INF/tld/struts-html.tld" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Résultats
<br/>
<jsp:getProperty name="user" property="nom"/><br/>
<jsp:getProperty name="user" property="message"/>
<br/><br/>
</body>
</html> |
Où est-ce que j'ai oublié un truc ? Merci de votre aide !