栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Struts MVC在没有usinf脚本的情况下在jsp中显示动态值

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Struts MVC在没有usinf脚本的情况下在jsp中显示动态值

将您的数据库读取代码移至动作控制器。它应该从db中读取所需的值,并将其放入请求或模型中。

比使用jstl输出值(在jsp中):

<c:out value="${parameterFromRequest}"/>

定义bean:

public class MyBean {    private final String tName;    private final String tFee;    public MyBean(String tName, String tFee) {        this.tName = tName;        this.tFee = tFee;    }    public String getTName() {        return tName;    }    public String getTFee() {        return tFee;    }}

在动作控制器中创建集合:

String sql = "Select tname,tfee from addtest order by tname";ResultSet rs = SQLC.getData(sql, null);Collection<MyBean> myBeans = new ArrayList<MyBean>();while (rs.next()) {    String testname = rs.getString("tname");    String testfee = rs.getString("tfee");    myBeans.add(new MyBean(testname, testfee));}request.setAttribute("myBeans", myBeans);

在jsp中访问:

<c:forEach var="myBean" items="${myBeans}">    Name: <c:out value="${myBean.tName}"/>    Fee: <c:out value="${myBean.tFee}"/></c:forEach>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/435735.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号