jsp 结合使用jstl 和 javabean
2014-01-13 11:59
393 查看
网上看到的javabean的代码都比较简单只是返回简单的String,但是实际使用中有时候可能会有需要一次返回多条数据的情况,下面例子就是使用List返回多条数据的例子,以此类推像dataset,table之类的数据应该也是可以这样得到的
javabean的代码,为了方便直接写的固定数据firstname
javabean的代码,为了方便直接写的固定数据firstname
package com.myapp.struts; import java.beans.*; import java.io.Serializable; import java.util.LinkedList; import java.util.List; public class NewBean implements Serializable { public static final String PROP_SAMPLE_PROPERTY = "sampleProperty"; private List<String> firstname; private String sampleProperty; private PropertyChangeSupport propertySupport; public NewBean() { propertySupport = new PropertyChangeSupport(this); } public String getSampleProperty() { return sampleProperty; } public void setSampleProperty(String value) { String oldValue = sampleProperty; sampleProperty = value; propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY, oldValue, sampleProperty); } public void addPropertyChangeListener(PropertyChangeListener listener) { propertySupport.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { propertySupport.removePropertyChangeListener(listener); } public List<String> getFirstname() { List<String> l = new LinkedList<String>(); l.add("1"); l.add("2"); return l; } public void setFirstname(List<String> firstname) { this.firstname = firstname; } }使用javabean的jsp页面,在写class的时候开始写的是NewBean总是找不到这个类,后来改成包含命名空间的全名才可以
<%@page import="com.myapp.struts.NewBean"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <jsp:useBean id="test1" class="com.myapp.struts.NewBean" scope="page"/> <c:forEach var="student" items="${test1.firstname}"> <p> ${student} </p> </c:forEach> <h1>Hello World!</h1> </body> </html>
相关文章推荐
- JSP 标准标签库(JSTL)与java代码段<%%>与js结合使用
- JSP+Javabean+JSTL实现了记录分页显示
- Jsp(javaBean中SetProperty getProperty的使用)
- 使用Jstl异常:HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"(使用forEach时出错)
- JSP中的JavaBean的基本使用方法
- 使用Maven配置Jstl出现异常:The absolute uri: http://java.sun.com/jsp/jstl/core cannot...
- 使用JSP + JAVABEAN + XML 开发的一个例子
- jasper综合使用-javabean结合实际业务-解决PDF中文
- JSP中<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>标签的使用
- java JSP开发之Spring中Bean的使用
- JSP作业4 - 使用JSP+JavaBean+Servlet实现用户登录注册页面
- 使用json时报错:nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
- 使用JSP + JAVABEAN + XML 开发的一个例子 (转自arielxp !Java)
- 使用jstl标签时提示The absolute uri: http://java.sun.com/jsp/jstl/core cannot
- jsp中使用jstl实现类似java的if-else功能的写法
- 【错误解决】[Maven]使用Maven配置Jstl出现异常:The absolute uri: http://java.sun.com/jsp/jstl/core cannot...
- 使用JSP + JAVABEAN + XML 开发的一个例子
- 恼人的The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved...错误,无奈用Struts的bean:write替代了JSTL的C:out
- jsp+jstl+servlet+javaBean+Mysql用户登录注册页面