0

我有一个名为“Commande”的 Bean,其属性为“client”和 Vector“achats”,该向量用于放置购买的物品。因此,当我调用“achat.html”并输入我的产品名称时,他将调用“panier.php”将其放在此向量上,当我转到“AfficherPanier.jsp”时,他会打印购买的文章,因此
单击时会出错关于“afficherPanier.jsp”:消息在 [enis.Commande] 类型的 bean 中找不到有关属性 [Achats] 的任何信息

achat.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Achat</title>
</head>
<body>
<form action="http://localhost:8080/AchatEnLigneMVC/Panier" method=GET>
Entrer l'article à acheter : <input type="text" name="achat"/><br>
<input type="submit" value="Valider"/>
</form>
</body>
</html>

Commande.java
package enis;

import java.util.Vector;

public class Commande {
    String client;
    Vector Achats = new Vector();
    public String getClient() {
        return client;
    }
    public void setClient(String client) {
        this.client = client;
    }
    public Vector getAchats() {
        return Achats;
    }
    public void setAchats(Vector achats) {
        Achats = achats;
    }

    
}
    
    ```
Panier.java
package enis;

public class Panier extends HttpServlet {
   private static final long serialVersionUID = 1L;
      
   /**
    * @see HttpServlet#HttpServlet()
    */
   public Panier() {
       super();
       // TODO Auto-generated constructor stub
   }

   /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       response.setContentType("text/html");
       PrintWriter out = response.getWriter();
       HttpSession session = request.getSession(true);
       Commande cmd=  new Commande();
       Vector v = new Vector();
       String newitem = request.getParameter("achat");
       v.addElement(newitem);
       cmd.setAchats(v);
       session.setAttribute("commande", cmd);
       response.sendRedirect("http://localhost:8080/AchatEnLigneMVC/Achat.html");
   }

   /**
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    */
   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       
   }

}
AfficherPanier.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Afficher Panier</title>
</head>
<body>
<jsp:useBean id="commande" class="enis.Commande" scope="session"/>
<jsp:getProperty property="Achats" name="commande"/>
</body>
</html>
4

1 回答 1

-2

请使用 Java 命名约定:

Vector achats = new Vector();

一旦在 bean 和 JSP 标记中使用小写字母achats,它就会起作用。

此外,无需初始化Vector.

于 2020-12-18T18:10:20.273 回答