tomcat的jsp-exampled的笔记1.
1.在jsp中$是运算的意思,还可以用来做比较如${5>8}返回false.要表示$这个字符,用 $.
当计算错误,自动报Infinity
2.
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="my" uri="http://jakarta.apache.org/tomcat/jsp2-example-taglib是假的地址
真的是这样定义的:
<taglib>
<taglib-uri>
http://jakarta.apache.org/tomcat/jsp2-example-taglib
</taglib-uri>
<taglib-location>
/WEB-INF/jsp2/jsp2-example-taglib.tld
</taglib-location>
</taglib>
3.tld引用
<%@ taglib prefix="my" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %>
也可以部署在 web.xml里 用tld的假名,这样更安全
<my:findBook var="book"/>
book.author //book是对象
my:caps(book.isbn) //caps 是tld文件里标出来的的函数:
4.tag引用
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
注意 没说是哪个 tag?它怎么知道用哪个tag
使用的时候就一句:
<tags:helloWorld/>
正好有个helloWorld.tag
^_^原来tag文件里面,装的就是jsp文件的零件,而tld主要用来做部署的
<tags:displayProducts>
<jsp:attribute >
Item: ${name}<br/>
Price: ${price}
</jsp:attribute>
<jsp:attribute >
Item: ${name}<br/>
<font color="red"><strike>Was: ${origPrice}</strike></font><br/>
<b>Now: ${salePrice}</b>
</jsp:attribute>
</tags:displayProducts>
attribute除了指定屬性文字之外,也可以將屬性當作Fragment傳入,方便在Tag File中作個別的處理
將attribute的屬性設定為Fragment,然後想取得指定的Fragment的話,就可以使用<jsp: invoke>動作元素,並指定Fragment的名稱
在tag里<jsp:invoke fragment="normalPrice"/><jsp:invoke fragment="onSale"/>
在jsp里<jsp:attribute >
5.bean的奇怪的地方.
public int getWeekOfYear() {....}
jsp引用中用
<jsp:useBean scope='page' type="dates.JspCalendar" />
<jsp:getProperty property="year"/>
事实上 源代码dates.JspCalendar.java里没有定义 year,居然能正确应用.
如果是只取get后的那看看这句:
getYear(){....};调用里是这样的:<jsp:getProperty property="year"/>
连大小写都部分了.
6.时间 调用
import java.text.DateFormat;
import java.util.*;
calendar = Calendar.getInstance();
Date trialTime = new Date();
calendar.setTime(trialTime);
7.一些有html标记
<td bgcolor="#010101"></td>
表格里加颜色感觉很部错
8.错误页面
<%@ page errorPage="errorpge.jsp" %>
被调用的页面
<%@ page isErrorPage="true" %>
方法:foo.getName().equalsIgnoreCase("integra")将此 String 与另一个 String 进行比较,不考虑大小写