View all fields / properties of bean in JSP / JSTL

后端 未结 4 1508
误落风尘
误落风尘 2020-12-23 09:53

I have a bean, ${product}. I would like to view all of the available fields / properties of this bean. So for instance, ${product.price}, ${p

4条回答
  •  无人及你
    2020-12-23 10:50

    There is nothing called JSTL Object. JSTL just provides the way to access java objects in JSP in cleaner and more readable way(other way is scriplet). Just implement toString(here is the link stating brief about toString method http://www.javatpoint.com/understanding-toString()-method) method in your java object in this case product and now

    1)If your question is how to print object properties in java

    System.out.println(product)
    

    2)To print it in JSP

     ${product}
    

    Here is toString method for your case

    public String toString(){
    return price + name;
    }
    

提交回复
热议问题