JSPѧϰ£¨Ò»£©
JSP»ù±¾Óï·¨
´ó²¿·ÖJSP±»Ò»¸öÒÔ“<%” ¿ªÍ·ºÍÒÔ“%>”½áβµÄµÄ±ê¼ÇÀ¨ÔÚÆäÖС£ÔÚ¸üеÄJSP 1.1¹æ·¶³ǫ̈ºó£¬¾ÍÓÐÁËÓëXML¼æÈݵİ汾¡£
JSPÖ¸ÁîºÍ½Å±¾ÔªËØ
Directives <%@ directive %>
Declarations <%! declaration %>
Expressions <%= expression %>
Code Fragment/Scriptlet <% code fragment %>
Comments <%-- comment --%>
µÚÒ»¸öJSP: Hello World
<%
String str1 = "Hello World!";
%>
<h2><%=str1%></h2>
<%
out.print("I'm OH.C");
%>
Êä³öÏÔʾΪ£º
Hello World!
I'm OH.C
Ö¸Áî
JSPÖ¸ÁîÊÇΪJSPÒýÇæ¶øÉè¼ÆµÄ¡£ËûÃDz¢²»Ö±½Ó²úÉúÈκοɼûÊä³ö£¬¶øÖ»ÊǸæËßÒýÇæÈçºÎ´¦ÀíÆäÓàJSPÒ³Ãæ¡£ÕâЩָÁîʼÖÕ±»À¨ÔÚ “<%@ ...%>”±ê¼ÇÖС£Á½¸ö×îÖØÒªµÄÖ¸ÁîÊÇ“page”ºÍ“Include”¡£“Taglib”Ö¸Áî²»ÔÚÌÖÂÛÖ®ÁУ¬µ«ÊÇÔÚÓÃJSP1.1´´½¨×Ô¶¨Òå±ê¼Ç¿ÉÒÔʹÓÃËü¡£
¼¸ºõÔÚËùÓÐJSPÒ³Ã涥²¿¶¼»á¿´µ½“Page”Ö¸Áî¡£¾¡¹Ü²»ÊDZØÐëµÄ£¬µ«Ëü¿ÉÒÔÈÃÄãÖ¸¶¨£º
µ½ºÎ´¦²éÕÒÆðÖ§³Ö×÷ÓõÄJavaÀà±ð£º
<%@ page import="java.util.Date" %>,
³öÏÖJavaÔËÐÐÎÊÌâʱ£¬½«ÍøÉϳåÀËÕßÒýÏòºÎ´¦£º
<%@ page errorPage="errorPage.jsp" %>,
»¹ÓÐÄãÊÇ·ñÐèÒª¹ÜÀíÓû§µÄ»á»°¼¶ÐÅÏ¢£¬ÕâЩÐÅÏ¢¿ÉÄÜÀ´×Ô¶à¸öÍøÒ³£º
<%@ page session="true" %>.
“Include”Ö¸Áî¿ÉÒÔ°ÑÄãµÄÄÚÈݷֳɸü¶à¿É¹ÜÀíµÄÔªËØ£¬±ÈÈç°üÀ¨Ò»¸öÆÕͨҳÃæҳü»òÒ³½ÅµÄÔªËØ¡£°üº¬µÄÍøÒ³¿ÉÒÔÊÇÒ»¸ö¹Ì¶¨µÄHTML Ò³Ãæ»ò¸ü¶àµÄJSPÄÚÈÝ£º
<%@ include file="200453092147.htm.jsp" %>
ÉùÃ÷
JSPÉùÃ÷ÓÃÀ´ÈÃÄ㶨ÒåÒ³Ã漶±äÁ¿£¬ÒÔ±£´æÐÅÏ¢»ò¶¨ÒåJSPÒ³ÃæµÄÆäÓಿ·Ö¿ÉÄÜÐèÒªµÄÖ§³Ö·½·¨¡£Èç¹ûÄã·¢ÏÖ´úÂëÌ«¶à£¬Í¨³£×îºÃ°ÑËüÃÇд³ÉÒ»¸ö¶ÀÁ¢µÄJavaÀà±ð¡£ÉùÃ÷Ò»°ã¶¼ÔÚ“<% %>”±ê¼ÇÖС£Ò»¶¨ÒªÒԷֺţ¨£»£©½áÊø±äÁ¿ÉùÃ÷£¬ÒòΪÈκÎÄÚÈݶ¼±ØÐëÊÇÓÐЧµÄJavaÓï¾ä£º
<% int i=0; %>¡£
±í´ïʽ
ÓÐÁËJSP±í´ïʽ£¬±í´ïʽÆÀ¹À½á¹û»á±»×ª»»³ÉÒ»¸ö×Ö·û´®£¬²¢ÇÒ±»Ö±½Ó°üÀ¨ÔÚÊä³öÒ³ÃæÖ®ÄÚ¡£JSP ±í´ïʽ°üº¬ÔÚ“<%= %>” ±ê¼ÇÖУ¬Ã»Óзֺţ¬³ý·ÇÔÚ¼ÓÒýºÅµÄ×Ö·û´®²¿·ÖʹÓ÷ֺš£
<%= i %>
<%= "Hello" %>
´úÂëƬ¶Î/½Å±¾Æ¬¶Î
´úÂëƬ¶Î/½Å±¾Æ¬¶Î
Ïà¹ØÎĵµ£º
String url="http://www.baidu.com";
ActionForward gotourl = new ActionForward(url);
gotourl.setPath(url);
gotourl.setRedirect(true);
return gotourl;
1.RequestDispatcher.forward()
¡¡¡¡ ÊÇÔÚ·þÎñÆ÷¶ËÆð×÷ÓÃ,µ±Ê¹ÓÃforward()ʱ,Servlet engine´ ......
application£ºÈ«¾Ö×÷Ó÷¶Î§£¬Õû¸öÓ¦ÓóÌÐò¹²Ïí£¬¾ÍÊÇÔÚ²¿ÊðÎļþÖеÄͬһ¸öwebApp¹²Ïí£¬ÉúÃüÖÜÆÚΪ£ºÓ¦ÓóÌÐòÆô¶¯µ½Í£Ö¹¡£
session£º»á»°×÷ÓÃÓò£¬µ±Óû§Ê״ηÃÎÊʱ£¬²úÉúÒ»¸öеĻỰ£¬ÒÔºó·þÎñÆ÷¾Í¿ÉÒÔ¼ÇסÕâ¸ö»á»°×´Ì¬¡£ÉúÃüÖÜÆÚ£º»á»°³¬Ê±£¬»òÕß·þÎñÆ÷¶ËÇ¿ÖÆʹ»á»°Ê§Ð§¡£
sessionÊÇÕë¶Ôµ¥¸ö¿Í»§ºÍ·þÎñÆ÷½øÐлỰµÄ  ......
Ò»¡¢JSPµÄ¼¼ÊõÔÀí
¶þ¡¢JSPµÄ×¢ÊͺÍÉùÃ÷
JSP×¢ÊÍÓÃÓÚ±íÃ÷ÔÚ³ÌÐò¿ª·¢¹ý³ÌÖеĿª·¢Ìáʾ£¬²»»áÊä³öµ½¿Í»§¶Ë£»
<%--×¢ÊÍÄÚÈÝ--%> —— JSP×¢ÊÍ
<£¡--×¢ÊÍÄÚÈÝ--£¡> —&md ......
ÏîÄ¿ÒªÇ󽫺ǫ́Êý¾Ý½øÐÐÏÔʾ£¨ÏÔʾҪÇ󲿷ÖÄÚÈݽøÐÐÁÐÏîºÏ²¢£©£¬ÔÚ¶ÔÏÔʾµÄÊý¾Ý½øÐе¼³ö³Éexcel
ʵÏÖ¹ý³Ì
1¡¢²éѯºÍµ¼³öµÄjspÒ³Ãæ ¹Ø¼ü´úÂë
<script language=javascript>
function exportExcel(){
/****ʵÏÖ·½·¨Ò»
<%-- var curTbl = document.getElementById("techQueryTab"); --%>
<%-- ......
ÈçºÎÓÃJBoss ......