jsp語法:
jsp指令元素
(1)include:導(dǎo)入其它文件夾
(2)page:
language:用什么語言,只能為java
contenttype:mime類型
import:導(dǎo)入java包
(3)taglib:自定義標簽庫
jsp常用標準元素
(1)jsp:forward:跳轉(zhuǎn)到其它頁面
(2)jsp:include:插入其它文件 eg:
(3)jsp:plugin:插入applet小程序
(4)jsp:param:參數(shù)傳值
jsp內(nèi)置對象
(1)request:常用方法
getparameter():提取表單元素的值
getremoteaddr():獲取客戶端ip值
(2)response:
sendredirect():重定向到其它網(wǎng)頁
setcontenttype();設(shè)置mime值
(3)out:向網(wǎng)頁輸出
(4)application
setattribute(string,object)把變量的值保存在application中;
getattribute(string)獲取保存在applicaion中的值
removeattribute(string)刪除保存在application中的值
(5)session
setattribute(string,object)把變量的值保存在session中;
getattribute(string)獲取保存在session中的值
removeattribute(string)刪除保存在
getid:獲取session編號
jsp簡單表單處理
<%@page contenttype="text/html;charset=gb2312"%><%@page language="java" %><html><head><title>表單處理</title></head> <form name="frm" method="get" action="ch-show.jsp"><table boder=0><tr><td>用戶名:</td><td><input type=text name="tname"></td></tr><tr><td>密碼:</td><td><input type=password name="tpass"></td></tr><tr><td>性別:</td><td><input type=radio name="tsex" value="男" checked>男<input type=radio name="tsex" value="女">女</td></tr><tr><td>愛好:</td><td><input type=checkbox name=tch1 value="體育">體育<input type=checkbox name=tch2 value="美術(shù)">美術(shù)<input type=checkbox name=tch3 value="音樂">音樂</td></tr><tr><td>專業(yè):</td><td><select name=ty><option value="計算機">計算機</option><option value="文學(xué)">文學(xué)</option><option value="數(shù)學(xué)">數(shù)學(xué)</option></select><tr><td>留言:</td><td><textarea name=tl rows=5 cols=20></textarea></td></tr><tr><td><input type=submit value="用戶信息"></td></tr></table></form> <%string tname=request.getparameter("tname");string tpass=request.getparameter("tpass");string tsex=request.getparameter("tsex");string tlove1=request.getparameter("tch1");string tlove2=request.getparameter("tch2");string tlove3=request.getparameter("tch3");string ty=request.getparameter("ty");string tl=request.getparameter("tl"); byte b1[]=tsex.getbytes("iso-8859-1");tsex=new string(b1);if(tlove1==null){tlove1="";}else{byte b2[]=tlove1.getbytes("iso-8859-1");tlove1=new string(b2);}if(ty==null){ty="";}else{byte b5[]=ty.getbytes("iso-8859-1");ty=new string(b5);}if(tlove2==null){tlove2="";}else{byte b3[]=tlove2.getbytes("iso-8859-1");tlove2=new string(b3);}if(tlove3==null){tlove3="";}else{byte b4[]=tlove3.getbytes("iso-8859-1");tlove3=new string(b4);} out.print("你的信息是:"+"<br>");out.print("用戶名"+tname+"<br>");out.print("密碼"+tname+"<br>");out.print("性別"+tsex+"<br>");out.print("愛好"+tlove1+tlove2+tlove3+"<br>");out.print("專業(yè)"+ty+"<br>");out.print("留言"+tl+"<br>");%></body> |