1. 程式人生 > >常用標簽(html+jstl+jsp)

常用標簽(html+jstl+jsp)

for 控制 bsp div span link alt 頁面 action

html:(form、input) (table、tr、td) div (a、 img、span) h1~h6 (select、option) (br、hr、center) (link、meta、script)

form常用屬性:action、method、enctype

action用來指定一個url,method一般使用post,比較安全,傳輸的內容比get大很多,enctype一般使用multipart/form-data,用來做文件上傳功能

1 <form action="" method="get" enctype="application/x-www-form-urlencoded"
></form>

input常用屬性:type、value、style,還有一些 鼠標點擊事件的屬性為列舉!

type的屬性值比較豐富,常用到的有text,password,reset,submit,button,image,file,hidden,

用來做提交功能一般建議用submit或者image,button也可以,但要結合js使用,hidden很有用,常做表單某一項的隱藏。file是結合文件上傳使用的。

1 <input type="text" value="" style="" />    

table常用屬性:border、cellpadding、cellspacing、align

1 <table border="" cellpadding="" cellspacing="" align="left" ></table>

a常用屬性:href target

1 <a href="" target=""></a>

img常用屬性:src alt

1 <img src="" alt="" />    

select常用屬性:name、style

option常用屬性:value、selected

1 <select name="" style="">
2       <option 
value="" selected="selected"></option> 3 </select>

link常用屬性:rel、type、href

1 <link rel="stylesheet" type="text/css" href=""/>

meta常用屬性:http-equiv、content

1   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

script常用屬性:type、language、src

1 <script type="" language="" src=""></script>

jstl:

jstl1.1版本開始支持EL表達式。EL 表達式必須以${XXX}來表示,其中“XXX”部分就是具體表達式的內容

使用jstl標簽需要引入兩個jar包:jstl.jar和standard.jar

然後在jsp頁面引入聲明:<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:if>標簽用於簡單的條件語句 ,test是條件判斷的內容,需要結合EL表達式進行操作。

1 <c:if test=""></c:if>

<c:forEach>為循環控制標簽 ,items需要通過EL表達式獲得

1 <c:forEach items="" var=""></c:forEach>

jsp:

<jsp:forward>用作頁面跳轉用,常用在index.jsp中。

1  <jsp:forward page="url"></jsp:forward>

<jsp:include>用來包含另一個.jsp文件,可以包含靜態文本和動態代碼。

1 <jsp:include page="url"></jsp:include>

小案例:

1    <select name="getter.id" style="width: 150px">  
2       <c:forEach items="${allEmployee }" var="allEmp">  
3            <c:if test="${allEmp.id!=emp.id }">      
4                <option value="${allEmp.id }">${allEmp.name }</option>
5             </c:if> 
6       </c:forEach> 
7    </select>
1 <form action="????url" method="post" enctype="multipart/form-data">
2             <input type="hidden" name="id" value="${emp.id }">
3             <input type="file" name="upload"/> <input type="submit"/>
4   </form>

常用標簽(html+jstl+jsp)