简体   繁体   中英

Print Property Vector in file jsp

I have a Bean called "Commande" with properties "client" and Vector "achats" this vector is used to put the articles purchased. so when i call "achat.html" and enter my product name he will call "panier.php" to put it on this vector and when i go to "AfficherPanier.jsp" he print the articles purchased so
there is an error when clicking on "afficherPanier.jsp": Message Cannot find any information on property [Achats] in a bean of type [enis.Commande]

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>

Please use Java naming convention:

Vector achats = new Vector();

Once you use lower case achats in your bean and in the JSP tag it will work.

Also, there is no need to initialize Vector .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM