JSTL之c标签
来源:百度文库 编辑:神马文学网 时间:2024/06/16 13:47:35
JSTL之c标签 收藏
Student.java:package com.myapp.beans; public class Student { private String sno; private String sname; private Integer sage; private String ssex; private String deptno; public Student(String sno, String sname, Integer sage, String ssex, String deptno) { this.sno = sno; this.sname = sname; this.sage = sage; this.ssex = ssex; this.deptno = deptno; } public String getDeptno() { return deptno; } public void setDeptno(String deptno) { this.deptno = deptno; } public Integer getSage() { return sage; } public void setSage(Integer sage) { this.sage = sage; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public String getSno() { return sno; } public void setSno(String sno) { this.sno = sno; } public String getSsex() { return ssex; } public void setSsex(String ssex) { this.ssex = ssex; } }
ShowServlet.java:package com.myapp.servlets; import java.io.IOException;import java.util.*;import javax.servlet.ServletException;import javax.servlet.http.*;import com.myapp.beans.Student; public class ShowServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //定义10个学生对象 Student s[] = new Student[10]; s[0] = new Student("s001","张三",15,"女","d002"); s[1] = new Student("s002","李四",15,"男","d002"); s[2] = new Student("s003","王五",16,"女",null); s[3] = new Student("s004","赵六",15,"男","d004"); s[4] = new Student("s005","田七",17,"女","d002"); s[5] = new Student("s006","周八",15,"男",null); s[6] = new Student("s007","付九",19,"女","d003"); s[7] = new Student("s008","王莹",16,"男",null); s[8] = new Student("s009","罗剑",15,"男","d002"); s[9] = new Student("s010","宇飞",15,"男","d002"); //将数据装入List List l = new ArrayList(); for(int i=0;i web.xml: ShowServlet com.myapp.servlets.ShowServlet ShowServlet /show
我们通过以上代码,虚拟出一些数据,供页面的标签调用,在实际项目中,可改为由数据库读取。
index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>JSTL之C标签
index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>JSTL之C标签
前进
我们通过标签,把一个可以显示的表格,保存到session对象的属性中,到下一页显示。 show.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> JSTL之C标签
注意这里的escapeXml="false"属性,如果为true,则会把HTML标签显示在网页里。
index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>JSTL之C标签 ${student.sname}
index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>JSTL之C标签 ${student.sname}
index.jsp:<%@page contentType="text/html;charset=UTF-8"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>JSTL之C标签 ${i} •
以上是简单的定义变量,指定其变化范围,循环显示。 index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>JSTL之C标签
这个例子与的类似,只是在循环时可以指定起始位子和步长。 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sony87615/archive/2009/10/15/4675501.aspx
Student.java:package com.myapp.beans; public class Student { private String sno; private String sname; private Integer sage; private String ssex; private String deptno; public Student(String sno, String sname, Integer sage, String ssex, String deptno) { this.sno = sno; this.sname = sname; this.sage = sage; this.ssex = ssex; this.deptno = deptno; } public String getDeptno() { return deptno; } public void setDeptno(String deptno) { this.deptno = deptno; } public Integer getSage() { return sage; } public void setSage(Integer sage) { this.sage = sage; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public String getSno() { return sno; } public void setSno(String sno) { this.sno = sno; } public String getSsex() { return ssex; } public void setSsex(String ssex) { this.ssex = ssex; } }
ShowServlet.java:package com.myapp.servlets; import java.io.IOException;import java.util.*;import javax.servlet.ServletException;import javax.servlet.http.*;import com.myapp.beans.Student; public class ShowServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //定义10个学生对象 Student s[] = new Student[10]; s[0] = new Student("s001","张三",15,"女","d002"); s[1] = new Student("s002","李四",15,"男","d002"); s[2] = new Student("s003","王五",16,"女",null); s[3] = new Student("s004","赵六",15,"男","d004"); s[4] = new Student("s005","田七",17,"女","d002"); s[5] = new Student("s006","周八",15,"男",null); s[6] = new Student("s007","付九",19,"女","d003"); s[7] = new Student("s008","王莹",16,"男",null); s[8] = new Student("s009","罗剑",15,"男","d002"); s[9] = new Student("s010","宇飞",15,"男","d002"); //将数据装入List List l = new ArrayList(); for(int i=0;i
我们通过以上代码,虚拟出一些数据,供页面的标签调用,在实际项目中,可改为由数据库读取。
index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
我们通过
注意这里的escapeXml="false"属性,如果为true,则会把HTML标签显示在网页里。
index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
index.jsp:<%@page contentType="text/html;charset=UTF-8"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
以上是简单的定义变量,指定其变化范围,循环显示。 index.jsp:<%@page contentType="text/html;charset=gb2312"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
这个例子与