无法将值从Bean设置为JSP页面 [英] Unable to set value from bean to JSP page

查看:62
本文介绍了无法将值从Bean设置为JSP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在bean中设置值的代码.

Here is my code to set value in bean.

Infobean infobean = new Infobean();
Session session =  HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();
String query="SELECT ifnull(max(CONVERT(id, SIGNED)),0) as maxId FROM infotable";
List<?> list = session.createSQLQuery(query).list();
int a = list.get(0).hashCode()+1;
String id = String.valueOf(a) ;
System.out.println(id);
infobean.setId(id);

在这里我想在JSP页面中使用该值.

Here I want to use that value in JSP page.

<td valign="top">
    <s:textfield  name="id" id="id" >
        <s:property value="%{id}" />
    </s:textfield>
</td>

在上面的代码中,我无法从bean设置该值.

In the above code, I was unable to set that value from bean.

推荐答案

要在jsp中显示bean值,您需要在action类中创建bean实例.假设DemoAction是calss,而Infobean是具有id属性的bean类.

To display bean value in jsp you need to create bean instance in action class. Suppose DemoAction is the calss and Infobean is bean class having id property.

 public class Infobean {
    private int id;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
 }
public class DemoAction {
    private Infobean info;
    public Infobean getInfo() {
        return info;
    }
    public void setInfo(Infobean info) {
        this.info = info;
    }
}

现在,您可以按如下所示显示属性值.

Now you can display the property value as follows.

<s:property value="info.id"/>

这篇关于无法将值从Bean设置为JSP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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