JSP标签
最近无聊,在网上看到很多JSP的博客,各种如何标签定义,恶心到不行...一怒之下写了几百行代码,常用的标签都写了实际使用的案例,效果图来一张
大致就这样了,下面贴代码
JSP页面代码
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.dfs.pojo.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
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>JSP标签</title>
</head>
<style type="text/css">
#ctrlDiv{
width: 100% ;
height: 1500px ;
background-color: yellow ;
}
.tagDiv1{
width: 40% ;
height: 1500px ;
float: left ;
background-color: #E8F2FE ;
}
.tagDiv2{
width: 30% ;
height: 1500px ;
float: left ;
background-color: #F0F0F0 ;
}
.tagDiv3{
width: 30% ;
height: 1500px ;
float: left ;
background-color: #99BFF1 ;
}
h3{
color: red ;
}
</style>
<body>
<%
int [] ages = {1,2,3,4,5,6} ;
List<String> list = new ArrayList<String>() ;
list.add("hello1") ;
list.add("hello2") ;
list.add("hello3") ;
// 重复内容不被遍历
Set<String> set = new TreeSet<String>(); // Set
set.add("One");
set.add("One");
set.add("Two");
set.add("Three");
set.add("Set");
Map<String, String> map = new HashMap<String, String>(); // Map
map.put("1", "黄彪");
map.put("2", "丫头");
map.put("3", "哥哥");
map.put("4", "笨蛋");
List<User> users = new ArrayList<User>(); // JavaBean的List
users.add(new User("黄彪", "xxxxxx"));
users.add(new User("昊天", "xxxxxx"));
users.add(new User("姐姐", "yyyyyy"));
users.add(new User("丫头", "zzzzzz"));
session.setAttribute("users", users); // 添加到session
%>
<div id="ctrlDiv">
<div class="tagDiv1">
<center>
<h1>数据显示C标签</h1>
<h3>C:OUT标签</h3>
<c:out value="${null}" default="没有数据"></c:out><br/&g