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

JSP腳本元素和注釋復(fù)習(xí)總結(jié)示例_JSP教程

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

推薦:JSP FusionCharts Free顯示圖表 具體實(shí)現(xiàn)
FusionCharts Free的下載地址:http://www.fusioncharts.com/goodies/fusioncharts-free/ 接下來(lái)在jsp頁(yè)面中引入js 復(fù)制代碼 代碼如下: script type=text/javascript src=FusionChartsFree/JSClass/FusionCharts.js/script 然后寫(xiě)入 復(fù)制代碼 代碼如下: script type=te

今天復(fù)習(xí)了JSP腳本元素和注釋部分,案例寫(xiě)出來(lái),大家自己調(diào)試下,整體總結(jié)如下,
1、JSP申明語(yǔ)句:
<%! 申明語(yǔ)句 %>
使用申明語(yǔ)句的變量為全局變量,多個(gè)用戶執(zhí)行此JSP頁(yè)面,將共享該變量。
如:

復(fù)制代碼 代碼如下:
<html>
<head>
<title>JSP Demo</title>
</head>
<body>
<%! int a = 1 ;%>
<%
out.println("a="+a);
a++;
%>
</body>
</html>


結(jié)果如下:
01.gif 
再次刷新,會(huì)發(fā)現(xiàn)如下a的值加一了,因?yàn)樽兞縜是全局變量,a++運(yùn)算多次累計(jì),多用客服端共享:
02.gif 
2、JSP Scriptlets:
<% Java代碼%>
在JSP Scriptlets中可包含多個(gè)語(yǔ)句,如:方法,變量, 表達(dá)式等;
如:

復(fù)制代碼 代碼如下:
<html>
<head>
<title>test demo</title>
</head>
<body>
<%
String str = "Hello,xiaomo!";
out.println(str);
%>
</body>
</html>


結(jié)果如下:
03.gif 
3、JSP表達(dá)式:
<%= Java代碼 %>
一種簡(jiǎn)單的輸出形式,必須有一個(gè)可以輸出的值,表達(dá)式中的代碼會(huì)首先執(zhí)行,然后轉(zhuǎn)換成字符串顯示到頁(yè)面。
如:

復(fù)制代碼 代碼如下:
<html>
<head>
<title>test demo</title>
</head>
<body>
<% String str = "Hello,xiaomo!"; %>
<%= str %>
</body>
</html>


結(jié)果如下:
04.gif 
4、JSP注釋?zhuān)?
<!-- --> HTML注釋?zhuān)瑫?huì)顯示于客戶端;
<%-- --%>JSP注釋?zhuān)粫?huì)顯示于客戶端;
如:

復(fù)制代碼 代碼如下:
<html>
<head>
<title>test demo</title>
</head>
<body>
<!-- 這是一個(gè)網(wǎng)頁(yè)注釋 -->
<%-- 這是一個(gè)JSP注釋 --%>
</body>
</html>


結(jié)果如下:
05.gif 
大家發(fā)現(xiàn)都沒(méi)有什么顯示,點(diǎn)擊瀏覽器右鍵查看源碼可以看到網(wǎng)頁(yè)注釋是在的,JSP注釋沒(méi)有,這個(gè)只有在JSP源碼才能看到:

復(fù)制代碼 代碼如下:
<html>
<head>
<title>test demo</title>
</head>
<body>
<!-- 這是一個(gè)網(wǎng)頁(yè)注釋 -->
</body>
</html>


應(yīng)該很多人都知道,JSP頁(yè)面是轉(zhuǎn)譯成Servlet后在通過(guò)服務(wù)器轉(zhuǎn)換成html代碼發(fā)送到客戶端顯示的,下面給大家看下本案例的JSP頁(yè)面轉(zhuǎn)換成Servlet后的源碼(其中紅色標(biāo)注為轉(zhuǎn)換成前臺(tái)的html代碼):

復(fù)制代碼 代碼如下:


/*
* Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/7.0.34
* Generated at: 2013-07-03 01:27:37 UTC
* Note: The last modified time of this file was set to
* the last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class HelloXiaoMo_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static final javax.servlet.jsp.JspFactory _jspxFactory =
javax.servlet.jsp.JspFactory.getDefaultFactory();
private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;
private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.tomcat.InstanceManager _jsp_instancemanager;
public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
return _jspx_dependants;
}
public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
}
public void _jspDestroy() {
}
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
response.setContentType("text/html;charset=utf-8");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\r\n");
out.write("<html>\r\n");
out.write("\t<head>\r\n");
out.write("\t\t<title>test demo</title>\r\n");
out.write("\t</head>\r\n");
out.write("\t<body>\r\n");
out.write("\t\t<!-- 這是一個(gè)網(wǎng)頁(yè)注釋 -->\r\n");
out.write("\t\t");
out.write("\r\n");
out.write("\t</body>\r\n");
out.write("</html>");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
else throw new ServletException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}

分享:網(wǎng)頁(yè)模板:關(guān)于jsp頁(yè)面使用jstl的異常分析
在jsp頁(yè)面中使用如下代碼加入jstl的支持,發(fā)現(xiàn)頁(yè)面如下異常,那么很有可能是你的Tomcat的lib目錄中沒(méi)有jstl的jar包,所以才導(dǎo)致tomcat無(wú)法解析jstl,解決方法如下,感興趣的朋友可以參考下哈 1.在jsp頁(yè)面中使用如下代碼加入jstl的支持 復(fù)制代碼 代碼如下: %@ taglib pre

來(lái)源:模板無(wú)憂//所屬分類(lèi):JSP教程/更新時(shí)間:2013-07-04
相關(guān)JSP教程