列表不在Java JSP中打印

时间:2015-10-18 18:34:55

标签: java jsp

我在Servlet中使用List<Members> ee = new ArrayList<>(); Two Members Objects然后将ee转发为request.getSession().setAttribute("ee", ee);,但是当我尝试在JSP页面中打印它时。什么都不显示

这是我放在JSP页面中的代码。

<c:forEach items="${ee}" var="item">
     <c:out value="${item.ID}"/><br />
</c:forEach>

这是会员班级代码。

public class Members {
    private int ID;
    private String name;
    private String email;
    public void setID(int id){
        this.ID=id;
    }
    public void setName(String name){
        this.name=name;
    }
    public void setEmail(String email){
        this.email=email;
    }
    public int getID(){
        return this.ID;
    }
    public String getName(){
        return this.name;
    }
    public String getEmail(){
        return this.email;
    } 
}

当我查看JSP页面的页面源时,我得到了这个源代码:

<c:forEach items="[Members@4a419a, Members@1b527b6]" var="item">
   <c:out value=""/><br />
</c:forEach>

1 个答案:

答案 0 :(得分:0)

如果您在页面源中看到jstl核心标记,则仅表示您的jsp未按原样处理您的jstl标记。 您需要在jsp中导入jstl标记,并在Web项目的类路径中包含jstl核心jar

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

        double subtotal = 0.00;
        int coffee = 0;
        double coffeePrice = 2.50;    

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main_relative);

            Button subtractCoffee = (Button) findViewById(R.id.subtractCoffeeButton);
            subtractCoffee.setOnClickListener(this);

            Button addCoffee = (Button) findViewById(R.id.addCoffeeButton);
            addCoffee.setOnClickListener(this);

    }



        @Override
        public void onClick(View v) {

        TextView coffeeTV = (TextView) findViewById(R.id.tvCoffeeOrder);
        TextView subTotalTV = (TextView) findViewById(R.id.tvSubtotalCost);


        switch (v.getId()) {
            case R.id.subtractCoffeeButton:
                if (coffee == 0) {
                    break;
                } else if (coffee == 1) {
                    coffee = 0;
                    coffeeTV.setText(Integer.toString(coffee));
                    break;
                } else {
                    coffee = coffee - 1;
                    coffeeTV.setText(Integer.toString(coffee));
                    subtotal = subtotal - coffeePrice;
                    subTotalTV.setText(Double.toString(subtotal));
                }
                break;
            case R.id.addCoffeeButton:
                coffee += 1;
                coffeeTV.setText(Integer.toString(coffee));
                subtotal = subtotal + coffeePrice;
                subTotalTV.setText(Double.toString(subtotal));
                break;
        }

    }