Récupérations données d'un formulaire
Bonjour à toutes et à tous,
Je souhaite récupérer les données d'un champ présent sur mon formulaire et l'afficher. Le problème c'est quand je clique sur valider il me sort une erreur à la ligne 20 (ma/actions/ClientAction.java)
Voici le code:
ClientAction.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
|
package ma.actions;
import ma.beans.Client;
import com.opensymphony.xwork2.ActionSupport;
public class ClientAction extends ActionSupport{
Client client;
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public String enregistrer(){
String nom = client.getNom();
if(nom.equals("")){
System.out.println("Veuillez remplir tout les champs");
return "input";
}else{
System.out.println("Sucess.........");
return "success";
}
}
} |
Client.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
package ma.beans;
public class Client {
private String nom;
c String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
} |
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>test2</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>client.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
|
<?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="jsp" namespace="/jsp" extends="struts-default">
<action name="register" class="ma.actions.ClientAction" method="enregistrer">
<result name="success" >/jsp/afficherClient.jsp</result>
<result name="input">/jsp/client.jsp</result>
</action>
</package>
</struts> |
client.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 27
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix ="s" uri="/struts-tags" %>
<!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>Ajouter Client</title>
</head>
<body>
<table>
<s:form action="register" method="post">
<tr>
<td><h3>Créer un client</h3></td>
</tr>
<tr>
<td>Nom: </td>
<td><s:textfield id="name" name="name"></s:textfield></td>
</tr>
<tr>
<td><s:submit id="send" name="send" value="Send"/></td>
</tr>
</s:form>
</table>
</body>
</html> |
merci d'avance