为什么 JSP 没有获取 Struts 2 操作字段 [英] Why JSP doesn't get Struts 2 action fields

查看:30
本文介绍了为什么 JSP 没有获取 Struts 2 操作字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 jsp 页面中打印字段时遇到了一个小问题.我已经使用 hibernate 管理了持久性.

I have a little problem with printing field in a jsp page. I've managed persistency with hibernate.

当我进入jsp页面时,它什么也不显示.如何修改jsp以打印scontrino的prodotti字段?

When I go to jsp page, it displays nothing. How can I modify jsp in order to print fields of prodotti of a scontrino?

动作类

public class ScontrinoStruts extends ActionSupport implements UserAware{
        
        private static java.lang.Float iva = 22.00f;
        
        private String valori;
    
        private int idScontrino;
        private Date data;
        private java.lang.Float importoTotale;
        private int totalePezzi;
        
        private int ID_Anagrafica;//idanagrafica
        private Anagrafica anagrafica;
        private AnagraficaDAO anagraficaDAO = AnagraficaDAOFactory.getDAO();
        
        private int idProdotto;
        private List<Prodotto> prodotti = new ArrayList<Prodotto>();
        private Prodotto prodotto;
    
        private Scontrino scontrino = new Scontrino();
        List<Scontrino> scontrini = new ArrayList<Scontrino>();
        ScontrinoDAO scontrinoDAO = ScontrinoDAOFactory.getDAO();
        ProdottoDAO prodottoDAO = ProdottoDAOFactory.getDAO();
        
        public String showScontrino(){
            scontrino = scontrinoDAO.getScontrino(idScontrino);
            return "success";
        }
        //getters and setters
    }

struts.xml

    <action name="showScontrino" method="showScontrino"
        class="it.unirc.pjam.Action.ScontrinoStruts">
        <result name="success">/scontrino.jsp</result>
    </action>

JSP

    <table>
        <tr>
            <td>id</td>
            <td>Descrizione</td>
            <td>prezzo</td>
        </tr>
        <s:iterator value="scontrino.prodotti">
            <tr>
                <td><s:property value="idProdotto" /></td>
                <td><s:property value="descrizione" /></td>
                <td><s:property value="prezzo" /></td>
            </tr>
        </s:iterator>
    </table>

推荐答案

通过 OGNL 表达式显示的字段,用于遍历对象属性以查找值.value 等属性用于在返回其值之前首先解析 OGNL 表达式.您可以在 this 答案中找到如何评估 OGNL 表达式.

The fields a displayed via OGNL expression that is used to traverse the object properties to find the value. Attributes such as value is used to parse for OGNL expression first before returning its value. How OGNL expression is evaluated you can find in this answer.

您还可以阅读 this 答案以了解 OGNL 在搜索值时使用的操作上下文是什么.

You can also read this answer to understand what is the action context that is used by OGNL when it's searching the values.

这个答案将指导您如何为迭代的列表提供 getter.

This answer will guide you how to provide getter for the list that is iterated.

通过这个答案深入了解OGNL语言指南.

Take a deep learning into OGNL language guide with this answer.

这个答案将教您如何使用点表示法访问 bean 的属性.

This answer will teach you how to use dot notation to access beans' properties.

这篇关于为什么 JSP 没有获取 Struts 2 操作字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆