JSP¶¯×÷
JSP¶¯×÷ÀûÓÃXMLÓï·¨¸ñʽµÄ±ê¼ÇÀ´¿ØÖÆServletÒýÇæµÄÐÐΪ¡£ÀûÓÃJSP¶¯×÷¿ÉÒÔ¶¯Ì¬µØ²åÈëÎļþ¡¢ÖØÓÃJavaBean×é¼þ¡¢°ÑÓû§Öض¨Ïòµ½ÁíÍâµÄÒ³Ã桢ΪJava²å¼þÉú³ÉHTML´úÂë¡£
JSP¶¯×÷°üÀ¨£º
jsp:include£ºÔÚÒ³Ãæ±»ÇëÇóµÄʱºòÒýÈëÒ»¸öÎļþ¡£
jsp:useBean£ºÑ°ÕÒ»òÕßʵÀý»¯Ò»¸öJavaBean¡£
jsp:setProperty£ºÉèÖÃJavaBeanµÄÊôÐÔ¡£
jsp:getProperty£ºÊä³öij¸öJavaBeanµÄÊôÐÔ¡£
jsp:forward£º°ÑÇëÇóתµ½Ò»¸öеÄÒ³Ãæ¡£
jsp:plugin£º¸ù¾Ýä¯ÀÀÆ÷ÀàÐÍΪJava²å¼þÉú³ÉOBJECT»òEMBED±ê¼Ç¡£
¡¡¡¡ 13.1 jsp:include¶¯×÷
¡¡¡¡ ¸Ã¶¯×÷°ÑÖ¸¶¨Îļþ²åÈëÕýÔÚÉú³ÉµÄÒ³Ãæ¡£ÆäÓï·¨ÈçÏ£º
£¼jsp:include page="relative URL" flush="true" /£¾
¡¡¡¡ Ç°ÃæÒѾ½éÉܹýincludeÖ¸ÁËüÊÇÔÚJSPÎļþ±»×ª»»³ÉServletµÄʱºòÒýÈëÎļþ£¬¶øÕâÀïµÄjsp:include¶¯×÷²»Í¬£¬²åÈëÎļþµÄʱ¼äÊÇÔÚÒ³Ãæ±»ÇëÇóµÄʱºò¡£jsp:include¶¯×÷µÄÎļþÒýÈëʱ¼ä¾ö¶¨ÁËËüµÄЧÂÊÒªÉÔ΢²îÒ»µã£¬¶øÇÒ±»ÒýÓÃÎļþ²»ÄÜ°üº¬Ä³Ð©JSP´úÂ루ÀýÈç²»ÄÜÉèÖÃHTTPÍ·£©£¬µ«ËüµÄÁé»îÐÔÈ´ÒªºÃµÃ¶à¡£
¡¡¡¡ ÀýÈ磬ÏÂÃæµÄJSPÒ³Ãæ°Ñ4ÔòÐÂÎÅÕªÒª²åÈëÒ»¸ö“What's New ?”Ò³Ãæ¡£¸Ä±äÐÂÎÅժҪʱֻÐè¸Ä±äÕâËĸöÎļþ£¬¶øÖ÷JSPÒ³ÃæÈ´¿ÉÒÔ²»×÷Ð޸ģº
¡¡¡¡ WhatsNew.jsp
£¼!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"£¾
£¼HTML£¾
£¼HEAD£¾
£¼TITLE£¾What's New£¼/TITLE£¾
£¼/HEAD£¾
£¼BODY BGCOLOR="#FDF5E6" TEXT="#000000" LINK="#0000EE"
VLINK="#551A8B" ALINK="#FF0000"£¾
£¼CENTER£¾
£¼TABLE BORDER=5 BGCOLOR="#EF8429"£¾
£¼TR£¾£¼TH CLASS="TITLE"£¾
What's New at JspNews.com£¼/TABLE£¾
£¼/CENTER£¾
£¼P£¾
Here is a summary of our four most recent news stories:
£¼OL£¾
£¼LI£¾£¼jsp:include page="news/Item1.html" flush="true"/£¾
£¼LI£¾£¼jsp:include page="news/Item2.html" flush="true"/£¾
£¼LI£¾£¼jsp:include page="news/Item3.html" flush="true"/£¾
£¼LI£¾£¼jsp:include page="news/Item4.html" flush="true"/£¾
£¼/OL£¾
£¼/BODY£¾
£¼/HTML£¾
¡¡¡¡ 13.2 jsp:useBean¶¯×÷
¡¡¡¡ jsp:useBean¶¯×÷ÓÃÀ´×°ÔØÒ»¸ö½«ÔÚJSPÒ³ÃæÖÐʹÓõÄJavaBean¡£Õâ¸ö¹¦Äܷdz£ÓÐÓã¬ÒòΪËüʹµÃÎÒÃǼȿÉÒÔ·¢»ÓJava×é¼þÖØÓõÄÓÅÊÆ£¬Í¬Ê±Ò²±ÜÃâÁËËðʧJSPÇø±ðÓÚServletµÄ·½±ãÐÔ¡£jsp:useBean¶¯×÷×î¼òµ¥µÄÓ﷨Ϊ£º
£¼jsp:useBean id="name" class="package.class" /£¾
¡¡¡¡
Ïà¹ØÎĵµ£º
Ö»Ðè´ÓÊý¾Ý¿â²é³öÀ´ºóÔÚÏÔʾµÄµØ·½ÓÃ<pre></pre>±êÇ©ÐÞÊΣ¬ÈçÏ£º
<!--
<div style="font-size:12px;color:green;text-align:left">
<pre>
<%=
&n ......
µÚÒ»ÖÖ²ÉÓÃÔ¤±àÒëÓï¾ä¼¯£¬ËüÄÚÖÃÁË´¦ÀíSQL×¢ÈëµÄÄÜÁ¦£¬Ö»ÒªÊ¹ÓÃËüµÄsetString·½·¨´«Öµ¼´¿É£º
String sql= "select * from users where username=? and password=?;
PreparedStatement preState = conn.prepareStatement(sql);
preState.setString(1, userName);
preState.setString(2, password);
ResultSet rs = ......
1.RequestDispatcher.forward()
¡¡¡¡ ÊÇÔÚ·þÎñÆ÷¶ËÆð×÷ÓÃ,µ±Ê¹ÓÃforward()ʱ,Servlet engine´«µÝHTTPÇëÇó´Óµ±Ç°µÄServlet or JSPµ½ÁíÍâÒ»¸öServlet,JSP »òÆÕͨHTMLÎļþ,Ò²¼´ÄãµÄformÌá½»ÖÁa.jsp,ÔÚa.jspÓõ½ÁËforward()Öض¨ÏòÖÁb.jsp,´ËʱformÌá½»µÄËùÓÐÐÅÏ¢ÔÚ b.jsp¶¼¿ÉÒÔ»ñµÃ,²ÎÊý×Ô¶¯´«µÝ.
¡¡¡¡µ«forward()ÎÞ·¨Öض¨ÏòÖ ......
4.1 ±íµ¥Êý¾Ý¸ÅÊö
¡¡¡¡ Èç¹ûÄãÔø¾Ê¹ÓùýWebËÑË÷ÒýÇ棬»òÕßä¯ÀÀ¹ýÔÚÏßÊéµê¡¢¹ÉƱ¼Û¸ñ¡¢»úƱÐÅÏ¢£¬»òÐí»áÁôÒ⵽һЩ¹Å¹ÖµÄURL£¬±ÈÈç“http://host/path?user=Marty+Hall&origin=bwi&dest=lax”¡£Õâ¸öURLÖÐλÓÚÎʺźóÃæµÄ²¿·Ö£¬¼´“user=Marty+Hall&origin=bwi&dest=lax”£¬¾ÍÊÇ±íµ¥Êý ......