Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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³ÌÐò

                                                 ÈçºÎÓÃJBoss ......

JSP»ù´¡

Ò»¡¢JSP¼ò½é
JSP (Java Server Pages)ÊÇ·þÎñÆ÷¶ËµÄ½Å±¾ÓïÑÔ£¬ÊÇÒ»ÖÖÔÚHTMLÒ³ÃæÖмÓÈëJavaÓïÑÔ¶øÉú³É¶¯Ì¬Ò³ÃæµÄ¼¼Êõ£º¼ÓÈëÁËеıêÇ©£¨<%£¬%>£¬…£©¡£
JSPÊÇÒÔJavaºÍServletΪ»ù´¡¿ª·¢¶ø³ÉµÄ¶¯Ì¬ÍøÒ³Éú³É¼¼Êõ£¬ËüµÄµ×²ãʵÏÖÊÇJava Servlet¡£
JSPÒ³ÃæÓÉHTML´úÂëºÍǶÈëÆäÖеÄJava´úÂëËù×é³É¡£·þÎñÆ÷ÔÚÒ³Ãæ±»¿Í» ......

JSPÖÐforward()ÓësendRedirect()Çø±ð

response.sendRedirect("display.jsp");
request.getRequestDispatcher("display.jsp").forward(request,response);
jspµÄÒ³ÃæÌøתÓÐÁ½ÖÖ·½·¨£ºRequestDispatcher.forward()·½·¨ºÍHttpServletResponse.sendRedirect()·½·¨¡£
¡¡¡¡ËüÃǵÄÇø±ðÊÇ£º
¡¡¡¡RequestDispatcher.forward()·½·¨½öÊÇÈÝÆ÷ÖпØÖÆȨµÄתÏò£¬ÔÚ¿Í»§¶Ëä ......

jsp ǰ̨֪ʶ×ܽá

Ò»¡¢×ܵÄÀ´ËµÕâ¸ö½×¶ÎÖ÷ҪѧϰÁËÒ»ÏÂÕâЩ·½ÃæµÄ֪ʶ
£¨1£©¶ÔÒѾ­ÕÆÎÕÁ˵ÄHTML½øÒ»²½ÊìϤºÍϸ»¯
£¨2£©ÒÔÇ°²»´óÊìϤµÄCSSÓиö¸ü½øÒ»²ãµÄÈÏʶµÄÕÆÎÕ
£¨3£©ÔÚVBscriptµÄ»ù´¡ÉÏÈ«ÃæѧϰÁËjavascript£¬½Å±¾ÓïÑÔ¿é¿ÉÒÔ˵»ù±¾µÄ¶¼Ó¦¸ÃÄÜ×öµÄ³öÀ´¡£
£¨4£©Ç°ÆÚÒ²¶ÔjavaÖеÄTCPЭÒéºÍUDPЭÒéϵͳµÄѧϰÁËÒ»±é£¬Ò²¾ÍÊÇSOCKET±à³ÌÒ»¿ ......

jspµÄpageEncodingºÍcontentType

pageEncodingÊÇjspÎļþ±¾ÉíµÄ±àÂë
contentTypeµÄcharsetÊÇÖ¸·þÎñÆ÷·¢Ë͸ø¿Í»§¶ËʱµÄÄÚÈݱàÂë
JSPÒª¾­¹ýÁ½´ÎµÄ“±àÂ딣¬µÚÒ»½×¶Î»áÓÃpageEncoding£¬µÚ¶þ½×¶Î»áÓÃutf-8ÖÁutf-8£¬µÚÈý½×¶Î¾ÍÊÇÓÉTomcat³öÀ´µÄÍøÒ³£¬ ÓõÄÊÇcontentType¡£
µÚÒ»½×¶ÎÊÇjsp±àÒë³É.java£¬Ëü»á¸ù¾ÝpageEncodingµÄÉ趨¶ÁÈ¡jsp£¬½á¹ûÊÇ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ