日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

新手的JSP學習心得之(一)(2)_JSP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:解析Hibernate+Struts結合開發(fā)
隨著Java技術的逐漸成熟與完善,作為建立企業(yè)級應用的標準平臺,J2EE平臺得到了長足的發(fā)展。借助于J2EE規(guī)范中包含的多項技術:Enterprise JavaBean(EJB)、Java Servlets(Servlet)、Java Server Pages( JSP )、Java Message Service(JMS)等,開發(fā)出了許多應用


(1) 
<%@page buffer="1kb"%> 
<% 
long i=0; 
for(i=0;i<10;i++) 

out.println("@@@@@@@@@@@@@@@@@"); 

%> 
<jsp:forward page="./index.html"> 
(2) 
<%@page buffer="1kb"%> 
<% 
long i=0; 
for(i=0;i<600;i++) 

out.println("@@@@@@@@@@@@@@@@@"); 

%> 
</jsp:forward>說明: 
1. 方法(1),(2)可以使用變量表示重定向地址;方法(3)不能使用變量表示重定向地址。 
String add="./index.html"; 
<jsp:forward page="add"> 
無法重定向到index.html中去 
String add=http://localhost:7001/index.html 
response.sendRedirect(add); 
可以重定向到http://localhost:7001/index.html中去。 
2. 采用方法(1),(2)request中變量(通過request.setAttribute()保存到request中值)不能在新頁面中采用,采用方法(3)能. 綜上,我們應該采用(1),(2)重定向比較好. </jsp:forward> 

四、JSP中正確應用類: 
應該把類當成JAVA BEAN來用,不要在<% %> 中直接使用. 如下代碼(1)經過JSP引擎轉化后會變?yōu)榇a(2): 
從中可看出如果把一個類在JSP當成JAVA BEAN 使用,JSP會根據它作用范圍把它保存到相應內部對象中. 
如作用范圍為request,則把它保存到request對象中.并且只在第一次調用(對象值為null)它時進行實例化. 而如果在<% %>中直接創(chuàng)建該類一個對象,則每次調用JSP時,都要重新創(chuàng)建該對象,會影響性能. 
代碼(1) 
<jsp:usebean id="test" scope="request" class="demo.com.testdemo"> 
</jsp:usebean> 
<% 
test.print("this is use java bean"); 

testdemo td= new testdemo(); 
td.print("this is use new"); 
%> 
代碼(2) 
demo.com.testdemo test = (demo.com.testdemo)request.getAttribute("test"); 
if (test == null) 

try 

test = (demo.com.testdemo) java.beans.Beans.instantiate(getClass().getClassLoader(),"demo.com.testdemo"); 

catch (Exception _beanException) 

throw new weblogic.utils.NestedRuntimeException("cannot instantiate ’demo.com.testdemo’",_beanException); 

request.setAttribute("test", test); 
out.print("\r\n"); 

out.print("\r\n\r\n\r\n"); 
test.print("this is use java bean"); 

testdemo td= new testdemo(); 
td.print("this is use new"); 

分享:解析Struts配置教程
Struts框架是目前流行的JSP開發(fā)框架,本文就其進行了基礎講解。 首先下載Struts軟件包,到http://struts.apache.org/下載Struts,Struts各版本的差異很大,這里已Struts1.2.9版本為例,解壓縮包內容如下: 1、在tomcat安裝目錄下的webapps目錄中建立一個webj

共2頁上一頁12下一頁
來源:模板無憂//所屬分類:JSP教程/更新時間:2010-03-11
相關JSP教程