Jsp不会得到struts2的行动领域 [英] Jsp doesn't get struts2 action fields

查看:83
本文介绍了Jsp不会得到struts2的行动领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jsp页面中打印字段时遇到了一些问题。我使用hibernate管理持久性。



当我转到jsp页面时,它什么都没显示。如何修改jsp以打印scontrino的 prodotti 字段?



动作类

  public class ScontrinoStruts extends ActionSupport implements UserAware {

private static java.lang.Float iva = 22.00f;

私人字符串valori;

private int idScontrino;
私人日期数据;
private java.lang.Float importoTotale;
private int totalePezzi;

private int ID_Anagrafica; // idanagrafica
私有Anagrafica anagrafica;
private AnagraficaDAO anagraficaDAO = AnagraficaDAOFactory.getDAO();

private int idProdotto;
私人列表< Prodotto> prodotti = new ArrayList< Prodotto>();
私人产品prodotto;

私人Scontrino scontrino =新Scontrino();
列表< Scontrino> scontrini = new ArrayList< Scontrino>();
ScontrinoDAO scontrinoDAO = ScontrinoDAOFactory.getDAO();
ProdottoDAO prodottoDAO = ProdottoDAOFactory.getDAO();

public String showScontrino(){
scontrino = scontrinoDAO.getScontrino(idScontrino);
返回成功;
}
// getters and setters
}

struts.xml

 < action name =showScontrinomethod =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:属性值=idProdotto/>< / td>
< td>< s:property value =descrizione/>< / td>
< td>< s:属性值=prezzo/>< / td>
< / tr>
< / s:iterator>
< / table>


解决方案

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

您也可以阅读这个回答,以了解什么是OGNL在搜索值时使用的动作上下文。



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



深入学习OGNL语言指南,答案。



这个答案将教你如何使用点符号来访问bean的属性。


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

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

Action Class

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>

解决方案

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.

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

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

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

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

这篇关于Jsp不会得到struts2的行动领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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