新手的JSP學習心得之(一)(2)_JSP教程
教程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
相關JSP教程:
- jsp response.sendRedirect不跳轉的原因分析及解決
- JSP指令元素(page指令/include指令/taglib指令)復習整理
- JSP腳本元素和注釋復習總結示例
- JSP FusionCharts Free顯示圖表 具體實現(xiàn)
- 網頁模板:關于jsp頁面使用jstl的異常分析
- JSP頁面中文傳遞參數(shù)使用escape編碼
- 基于jsp:included的使用與jsp:param亂碼的解決方法
- Java Web項目中連接Access數(shù)據庫的配置方法
- JDBC連接Access數(shù)據庫的幾種方式介紹
- 網站圖片路徑的問題:絕對路徑/虛擬路徑
- (jsp/html)網頁上嵌入播放器(常用播放器代碼整理)
- jsp下顯示中文文件名及絕對路徑下的圖片解決方法
- 相關鏈接:
- 教程說明:
JSP教程-新手的JSP學習心得之(一)(2)
。