我想在jsp页面中显示所有发布的列表。我正在使用struts。我的listArticles函数抛出了如下所述的错误。
文章行动:
package action;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.opensymphony.xwork2.ActionSupport;
import dao.Article;
import service.ServiceArticle;
public class ArticleAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String designation;
private double prix;
List<Article> listArticle;
ServiceArticle serviceArticle = new ServiceArticle();
@Override
public void validate() {
if (StringUtils.isEmpty(getDesignation())) {
addFieldError(designation, "Saisir la designation");
}
if (StringUtils.isEmpty(String.valueOf(getPrix()))) {
addFieldError(designation, "Saisir la designation");
}
}
public String execute() {
Article article = new Article(designation, prix);
if (serviceArticle.addArticle(article)) {
listArticle = serviceArticle.getAllArticle();
return SUCCESS;
} else {
return ERROR;
}
}
public String listArticles() {
listArticle = serviceArticle.getAllArticle();
return SUCCESS;
}
/**
* @return the designation
*/
public String getDesignation() {
return designation;
}
/**
* @param designation
* the designation to set
*/
public void setDesignation(String designation) {
this.designation = designation;
}
/**
* @return the prix
*/
public double getPrix() {
return prix;
}
/**
* @param prix
* the prix to set
*/
public void setPrix(double prix) {
this.prix = prix;
}
/**
* @return the listArticle
*/
public List<Article> getListArticle() {
return listArticle;
}
/**
* @param listArticle
* the listArticle to set
*/
public void setListArticle(List<Article> listArticle) {
this.listArticle = listArticle;
}
}
struts.xml中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="Ajouter">
<result>/Article.jsp</result>
</action>
<action name="Article" class="action.ArticleAction" >
<result name="success">/ListArticle.jsp</result>
<!-- <result name="error">/Article.jsp</result> -->
</action>
<action name="listArticle" class="action.ArticleAction" method="listArticles">
<result name="SUCCESS">/ListArticle.jsp</result>
</action>
</package>
</struts>
ListArticle.jsp
<%@ 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>Insert title here</title>
</head>
<body>
<h3>Liste des Articles</h3>
<%-- <s:property name="listArticle" /> --%>
<table>
<thead>
<tr>
<th>DESIGNATION</th>
<th>PRIX</th>
</tr>
</thead>
<tbody>
<s:iterator value="listArticle">
<tr>
<td><s:property value="designation" /></td> <td><s:property value="prix" /></td>
</tr>
</s:iterator>
</tbody>
</table>
</body>
</html>
我做错了什么?我该怎么办?