jsp文件中的java打印属性向量

2jcobegt  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(267)

我有一个名为“commande”的bean,属性为“client”和向量“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>
whitzsjs

whitzsjs1#

请使用java命名约定:

Vector achats = new Vector();

一旦你用小写 achats 在bean和jsp标记中,它将工作。
而且,不需要初始化 Vector .

相关问题