c:forEach传递参数(jsp)

1、模型层

/**
 * @Title:Vote.java
 * @Package:com.you.vote.domain
 * @Description:投票主题对象
 * @author:Youhaidong(游海东)
 * @date:2013-8-3 上午9:48:21
 * @version V1.0
 */
package com.you.vote.domain;

import java.io.Serializable;

/**
 * 类功能说明
 * 类修改者 修改日期
 * 修改说明
 * <p>Title:Vote.java</p>
 * <p>Description:游海东个人开发</p>
 * <p>Copyright:Copyright(c)2013</p>
 * @author:游海东
 * @date:2013-8-3 上午9:48:21
 * @version V1.0
 */
public class Vote implements Serializable {

	/**
	 * @Fields  serialVersionUID:序列化
	 */
	private static final long serialVersionUID = 1L;
	
	//投票主题编号
	private Integer voteId;
	//投票主题
	private String title;
	//创建时间
	private String createDate;
	//投票类型
	private Integer type;
	//是否公布
	private Integer publish;
	//管理员编号
	private Integer adminId;
	
	/**
	 * <p>Title:</p>
	 * <p>Description:无参构造函数</p>
	 */
	public Vote() {
		super();
	}

	/**
	 * <p>Title:</p>
	 * <p>Description:有参构造函数</p>
	 * @param title
	 * @param createDate
	 * @param type
	 * @param publish
	 * @param adminId
	 */
	public Vote(String title, String createDate, Integer type, Integer publish,
			Integer adminId) {
		super();
		this.title = title;
		this.createDate = createDate;
		this.type = type;
		this.publish = publish;
		this.adminId = adminId;
	}

	/**
	 * @return the voteId
	 */
	public Integer getVoteId() {
		return voteId;
	}

	/**
	 * @param voteId the voteId to set
	 */
	public void setVoteId(Integer voteId) {
		this.voteId = voteId;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the createDate
	 */
	public String getCreateDate() {
		return createDate;
	}

	/**
	 * @param createDate the createDate to set
	 */
	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	/**
	 * @return the type
	 */
	public Integer getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(Integer type) {
		this.type = type;
	}

	/**
	 * @return the publish
	 */
	public Integer getPublish() {
		return publish;
	}

	/**
	 * @param publish the publish to set
	 */
	public void setPublish(Integer publish) {
		this.publish = publish;
	}

	/**
	 * @return the adminId
	 */
	public Integer getAdminId() {
		return adminId;
	}

	/**
	 * @param adminId the adminId to set
	 */
	public void setAdminId(Integer adminId) {
		this.adminId = adminId;
	}	

}

2、JSP传递参数(错误)

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>表格</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    <form action="">
       <table>
          <tr>
            <th>投票主题编号</th>
            <th>投票主题</th>
            <th>创建时间</th>
            <th>投票类型</th>
            <th>是否公布</th>
            <th>管理员编号</th>
          </tr>
          <c:forEach items="${voteList}" var="vote">
             <tr>
               <td>${vote.getVoteId}</td>
               <td>${vote.getTitle}</td>
               <td>${vote.getCreateDate}</td>
               <td>${vote.getType}</td>
               <td>${vote.getPublish}</td>
               <td>${vote.getAdminId}</td>
             </tr>
          </c:forEach>
       </table>
    </form>
  </body>
</html>

3、JSP传递参数(正确)

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>表格</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    <form action="">
       <table>
          <tr>
            <th>投票主题编号</th>
            <th>投票主题</th>
            <th>创建时间</th>
            <th>投票类型</th>
            <th>是否公布</th>
            <th>管理员编号</th>
          </tr>
          <c:forEach items="${voteList}" var="vote">
             <tr>
               <td>${vote.voteId}</td>
               <td>${vote.title}</td>
               <td>${vote.createDate}</td>
               <td>${vote.type}</td>
               <td>${vote.publish}</td>
               <td>${vote.adminId}</td>
             </tr>
          </c:forEach>
       </table>
    </form>
  </body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值