jspÎļþ¿ªÍ·path, basePath×÷ÓÃ
ÔÚJSPÖеÄÈç¹ûʹÓà "Ïà¶Ô·¾¶" ÔòÓпÉÄÜ»á³öÏÖÎÊÌâ.
ÒòΪ ÍøÒ³ÖÐµÄ "Ïà¶Ô·¾¶" , ËûÊÇÏà¶ÔÓÚ "URLÇëÇóµÄµØÖ·" ȥѰÕÒ×ÊÔ´.
ÉÏÃæÕâ¾ä»°ÊÇʲôÒâ˼ÄØ ?
¾Ù¸öÀý×Ó:
¼ÙÈçÎÒÃÇÓÐÒ»¸öÏîÄ¿: MyApp
ÔÚ¸ÃÏîÄ¿ÏÂ, ÓÐÒ»¸öjspÎļþ¼Ð
¸ÃÎļþ¼ÐÏ°üÀ¨:
login.jsp // µÇ½ҳÃæ
register.jps // ×¢²áÒ³Ãæ
ÎÒÃÇÔÚä¯ÀÀÆ÷ÖÐÊäÈëµØÖ· (×¢Òâ: µØÖ·µÄÄÚÈÝ):
http://localhost:8080/MyApp/jsp/login.jsp
Õâʱºò, ä¯ÀÀÆ÷»áÁ´½Óµ½ "µÇ½ҳÃæ" (login.jsp)
ÔÚlogin.jspÎļþÄÚ°üº¬ÁËÈçÏ "²¿·Ö´úÂë":
<a href="jsp/register.jsp">×¢²áÓû§ </a>
ÄÇô,Èç¹ûÎÒÃǵã»÷Õâ¸öÁ´½Ó,¾Í»áÔÚä¯ÀÀÆ÷µØÖ·À¸ÖÐ, ³öÏÖÈçÏ´íÎóÁ´½Ó:
http://localhost:8080/MyApp/jsp/jsp/register.jsp
¿´~~
Ϊʲô»á³öÏÖ"/jsp/jsp/register.jsp"ÄØ?
ÒòΪ, ÍøÒ³ÖеÄ"Ïà¶ÔÁ´½Ó", ÊÇÏà¶ÔÓÚÄãËù "ÇëÇóµÄURL·¾¶" Ëù¾ö¶¨µÄ.
¼´:
ÒòΪÕâÀïÇëÇ󷾶ÊÇ:http://localhost:8080/MyApp/jsp/login.jsp
ÄÇô, ä¯ÀÀÆ÷ ¾Í»áÔÚÕâ¸ö·¾¶ÏÂ(¼´:http://localhost:8080/MyApp/jsp/)È¥ÕÒ jsp/register.jsp
ËùÒԾͻá³öÏÖÈçÏ´íÎóÄÚÈÝ:
http://localhost:8080/MyApp/jsp/jsp/register.jsp
ÉÏÃæµÄÎÊÌ⣬¾ÍÊǵ÷ÓÃÒ³ÃæºÍ±»µ÷ÓÃÒ³ÃæµÄURL²»Í¬ËùÔì³ÉµÄ£¬
´ËÀà´íÎóÒ²³£³£»á³öÏÖÔÚ2¸öÒ³ÃæÖ®¼ä½øÐÐ "ת·¢"(forward) ²Ù×÷µÄʱºò¡£
ÒòΪforwardÊÇÔÚºǫ́½øÐеģ¬¶Ô¿Í»§¶ËÀ´ËµÊÇ͸Ã÷µÄ¡£(¼´: URL²»¸Ä±ä£¬¶øÊý¾ÝÄÚÈÝÈ´ÊÇÁíÒ»¸öÒ³Ãæ·µ»ØÀ´µÄ¡£¡£¡£)
ÄÇôÈçºÎ½â¾öÕâÎÊÌâÄØ£¿
(Ò»)·½·¨Ò»£ºÖ±½Ó²ÉÓþø¶Ô·¾¶ (²»ÍƼö)
ÔÚJSPÒ³Ãæ¶Ë£¬»ñµÃ±¾ÏîÄ¿µÄ¾ø¶ÔµØÖ·£¨Èç¹ûÄãµÄÏîÄ¿½ÐMyApp£¬ÄÇô»ñµÃµ½µÄµØÖ·¾ÍÊÇ http://localhost:8080/MyApp/£©:
´úÂëÈçÏÂ:
<!-- **************·½·¨Ò»***************** -->
<%@ page language="java" pageEncoding="GBK" contentType="text/html;charset=gbk" isELIgnored="false"%>
<%
String path = request.getContextPath();
// »ñµÃ±¾ÏîÄ¿µÄµØÖ·(ÀýÈç: http://localhost:8080/MyApp/)¸³Öµ¸øbasePath±äÁ¿
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPo
Ïà¹ØÎĵµ£º
ÈçºÎÓÃJBoss ......
Ò»¡¢JSP¼ò½é
JSP (Java Server Pages)ÊÇ·þÎñÆ÷¶ËµÄ½Å±¾ÓïÑÔ£¬ÊÇÒ»ÖÖÔÚHTMLÒ³ÃæÖмÓÈëJavaÓïÑÔ¶øÉú³É¶¯Ì¬Ò³ÃæµÄ¼¼Êõ£º¼ÓÈëÁËеıêÇ©£¨<%£¬%>£¬…£©¡£
JSPÊÇÒÔJavaºÍServletΪ»ù´¡¿ª·¢¶ø³ÉµÄ¶¯Ì¬ÍøÒ³Éú³É¼¼Êõ£¬ËüµÄµ×²ãʵÏÖÊÇJava Servlet¡£
JSPÒ³ÃæÓÉHTML´úÂëºÍǶÈëÆäÖеÄJava´úÂëËù×é³É¡£·þÎñÆ÷ÔÚÒ³Ãæ±»¿Í» ......
response.sendRedirect("display.jsp");
request.getRequestDispatcher("display.jsp").forward(request,response);
jspµÄÒ³ÃæÌøתÓÐÁ½ÖÖ·½·¨£ºRequestDispatcher.forward()·½·¨ºÍHttpServletResponse.sendRedirect()·½·¨¡£
¡¡¡¡ËüÃǵÄÇø±ðÊÇ£º
¡¡¡¡RequestDispatcher.forward()·½·¨½öÊÇÈÝÆ÷ÖпØÖÆȨµÄתÏò£¬ÔÚ¿Í»§¶Ëä ......
Ò»¡¢×ܵÄÀ´ËµÕâ¸ö½×¶ÎÖ÷ҪѧϰÁËÒ»ÏÂÕâЩ·½ÃæµÄ֪ʶ
£¨1£©¶ÔÒѾÕÆÎÕÁ˵ÄHTML½øÒ»²½ÊìϤºÍϸ»¯
£¨2£©ÒÔÇ°²»´óÊìϤµÄCSSÓиö¸ü½øÒ»²ãµÄÈÏʶµÄÕÆÎÕ
£¨3£©ÔÚVBscriptµÄ»ù´¡ÉÏÈ«ÃæѧϰÁËjavascript£¬½Å±¾ÓïÑÔ¿é¿ÉÒÔ˵»ù±¾µÄ¶¼Ó¦¸ÃÄÜ×öµÄ³öÀ´¡£
£¨4£©Ç°ÆÚÒ²¶ÔjavaÖеÄTCPÐÒéºÍUDPÐÒéϵͳµÄѧϰÁËÒ»±é£¬Ò²¾ÍÊÇSOCKET±à³ÌÒ»¿ ......
pageEncodingÊÇjspÎļþ±¾ÉíµÄ±àÂë
contentTypeµÄcharsetÊÇÖ¸·þÎñÆ÷·¢Ë͸ø¿Í»§¶ËʱµÄÄÚÈݱàÂë
JSPÒª¾¹ýÁ½´ÎµÄ“±àÂ딣¬µÚÒ»½×¶Î»áÓÃpageEncoding£¬µÚ¶þ½×¶Î»áÓÃutf-8ÖÁutf-8£¬µÚÈý½×¶Î¾ÍÊÇÓÉTomcat³öÀ´µÄÍøÒ³£¬ ÓõÄÊÇcontentType¡£
µÚÒ»½×¶ÎÊÇjsp±àÒë³É.java£¬Ëü»á¸ù¾ÝpageEncodingµÄÉ趨¶ÁÈ¡jsp£¬½á¹ûÊÇ ......