zoukankan      html  css  js  c++  java
  • 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>
    


  • 相关阅读:
    JavaSE之流程控制结构
    JavaSE的基本语法
    排序算法
    Java实现归并排序
    Java中线程池的介绍
    Java锁的升降级及synchoronized优化
    ThreadLocal应用与原理
    spring bean 实例化bean前后进行相应的设置
    maven依赖配置和依赖范围
    springmvc校验
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315731.html
Copyright © 2011-2022 走看看