¹ØÓÚJSPÖÐrequest.getRealPath()
ÔÚΪ·þÎñÆ÷¶Ë×é¼þ±à³Ìʱ£¬ÄãºÜ¿ÉÄÜÒª´ÓÏà¶ÔÓÚweb¸ùµÄ·¾¶À´È¡µÃij¸öÎļþµÄÕæʵ·¾¶£¬µ«´ËÎļþʵ¼ÊÉÏÔÚÕ¾µãµÄÒ»¸öÐéÄâ·¾¶ÉÏ¡£
ʲôÊÇÐéÄâ·¾¶£¿
ÔÚÒ»¸öweb·þÎñÆ÷ÉÏ£¬ÐéÄâ·¾¶½«ÎïÀíÉÏ·ÖÀëµÄ¸÷Îļþ×éºÏÔÚÒ»Æ𣬷ÅÔÚͬһ¸öÕ¾µã·¾¶ÉÏ£¬ÔÚÓ¦Ó÷þÎñÆ÷ÉÏ£¬Ã¿¸öÓ¦Óö¨Î»ÓÚÆä×Ô¼ºµÄÐéÄâ·¾¶ÉÏ£¬Êµ¼ÊÉÏÏ໥֮¼äÓÐ×ÅÍêÃÀµØ·ÖÀë¡£
getRealPath()·½·¨
JSP servlet APIÌṩÁËgetRealPath(path)·½·¨£¬·µ»Ø¸ø¶¨ÐéÄâ·¾¶µÄÕæʵ·¾¶£¬Èç¹ûת»»´íÎó£¬Ôò·µ»Ønull¡£
getRealPathÓï·¨¶¨Ò壺
¡¡ public java.lang.String getRealPath(java.lang.String path)
¡¡ ·µ»ØÒ»¸ö×Ö·û´®£¬°üº¬Ò»¸ö¸ø¶¨ÐéÄâ·¾¶µÄÕæʵ·¾¶¡£ÀýÈ磬ÐéÄâ·¾¶ "/index.html"
²»¹ÜÔÚ·þÎñÆ÷ÎļþϵͳÉϾßÓÐÔõÑùµÄÕæʵ·¾¶£¬Ê¹ÓÃ"/index.html"×Ü¿ÉÒÔÕÒµ½Ëü¡£·µ»ØµÄÕæʵ·¾¶Ê¹ÓÃÁËÏà½üÓÚservletÈÝÆ÷(srvlet container)ËùÔÚ¼ÆËã»ú»ò²Ù×÷ϵͳµÄ¸ñʽ£¬°üº¬ÁËÊʵ±µÄ·¾¶·Ö¸ô·û¡£Èç¹ûservletÈÝÆ÷ÎÞ·¨×ª»»ÔòÕâ¸ö·½·¨½«·µ»Ønull¡£
¡¡ ²ÎÊý£º
¡¡ ¡¡ path -Ò»¸öÃèÊöÁËÐéÄâ·¾¶µÄ×Ö·û´®
¡¡ ·µ»ØÖµ£º
¡¡ ¡¡ ÃèÊöÕæʵ·¾¶µÄ×Ö·û´®»òÕßnull
Òź¶µÄÊÇ£¬getRealPath³£³£·µ»Ø²»Í¬µÄ¶«Î÷£¬ÕâÈ¡¾öÓÚ·þÎñÆ÷»òjspÎļþµ÷Óô˷½·¨µÄ·¾¶Î»Öá£
Ò»¸öexampleÕ¾µã
¼ÙÉèÎÒÃǵÄÕ¾µã×éÖ¯ÈçÏ£º
¸ù·¾¶°üº¬ÁËÎÒÃǵÄÕ¾µãµÄ¸ù£º http://address/
a_virtualĿ¼°üº¬ÁËÎÒÃÇÕ¾µãÌṩµÄÐéÄâ·¾¶µÄÎļþ£¬ÀýÈ磺
http://addess/virtual_dir/
ÎÒÃDzéÕÒfile1.txtºÍfile2.txtµÄÕæʵ·¾¶£¬ËüÃÇÒ»¸öÔÚÕ¾µã¸ù·¾¶Ï£¬Ò»¸öÔÚÐéÄâ·¾¶Ï¡£
getRealPath("/file1.txt") Ó¦¸Ã·µ»Ø“C:\site\site_root\file1.txt"£¬
getRealPath("/virtual_dir/file2.txt")Ó¦¸Ã·µ»Ø"C:\site\a_virtual\file2.txt"
getRealPath("/file3.txt")Ó¦¸Ã·µ»Ønull£¬ÒòΪÕâ¸öÎļþ²»´æÔÚ¡£
µ«getRealPath()²¢²»×ÜÊÇ·µ»ØͬÑùµÄ½á¹û£¬Õ⻹ȡ¾öÓëÄãʹÓõÄjsÒýÇæ¡£
JSPÒýÇæ
Tomcat 3.1
Tomcat·µ»ØµÄ½á¹û¾ßÓÐÓ¦ÓõĶÀÁ¢ÐÔ£¨application dependant£©£º
ËüÈ¡¾öÓëµ÷ÓÃgetRealPath·½·¨µÄÄǸöjspÎļþËùÔÚµÄλÖá£
ʵ¼ÊÉÏ£¬µ±page1.jsp (λÓÚÕ¾µã¸ù´¦)¶Ôfile1.txtºÍfile2.txtµ÷ÓÃtxtgetRealPath(), Ëü·µ»ØÕýÈ·µÄ½á¹û¡£(ÕâÊÇÔÚtomcat 3.1, 3.0°æÔò¶Ôfile2.txt·µ»Ø´íÎóµÄ·¾¶)
µ«Êǵ±page2.jsp(λÓÚÁíÒ»¸öÓ¦ÓÃ,ÔÚÒ»¸öÐéÄâ·¾¶ÖÐ)µ÷ÓÃgetRealPath£¬Ëü·µ»ØÁË´íÎóµÄ·¾¶£ºËüÁ¬½ÓÁ˸ÃjspÎļþËùÔڵķ¾¶ºÍÇëÇóµÄÐéÄâ·¾¶¡£
ÀýÈ磬´Ópage2.js
Ïà¹ØÎĵµ£º
ÔÚJSPÀ»ñÈ¡¿Í»§¶ËµÄIPµØÖ·µÄ·½·¨ÊÇ£ºrequest.getRemoteAddr£¨£©£¬ÕâÖÖ·½·¨Ôڴ󲿷ÖÇé¿ö϶¼ÊÇÓÐЧµÄ¡£µ«ÊÇÔÚͨ¹ýÁË
Apache£¬SquidµÈ·´Ïò´úÀíÈí¼þ¾Í²»ÄÜ»ñÈ¡µ½¿Í»§¶ËµÄÕæʵIPµØÖ·ÁË¡£Èç¹ûʹÓÃÁË·´Ïò´úÀíÈí¼þ£¬ÓÃ
request.getRemoteAddr£¨£©·½·¨»ñÈ¡µÄIPµØÖ·ÊÇ£º127.0.0.1»ò
192.168.1.110£¬¶ø²¢²»ÊÇ¿ ......
MyEclipse:ÐÞ¸ÄMyEclipse¿ª·¢¹¤¾ßÖеÄÒ³ÃæÄ£°å£¨JSPºÍHTMLµÈ£©
1.ÓÃMyEclipse¹¤¾ß¿ª·¢WebÏîÄ¿£¬ÓÐÒ»¸öºÜÆÕ±éµÄÎÊÌ⣬¾ÍÊÇÔÚн¨Ò»¸öÒ³ÃæÎļþʱ£¬ÐèÒªÐÞ¸ÄpageEncodingÖµ£¬Ò³ÃæÖÐĬÈϵÄpageEncodingÖµÒ»°ãÊÇISO-8859-1¡£
2.Èç¹ûWebÏîÄ¿ÐèÒªÖ§³ÖÖÐÎÄ£¬ÄǾͱØÐë°ÑÄǸöISO-8859-1¸ø¸Äµô£¬»»³ÉÒÔϼ¸ÖÖ£ºUTF-8¡¢GB2312 ......
a.jspÒ³ÃæÄÚÈÝ£º
%26lt;%@ page language£½"java" import£½"java.util." pageEncoding£½"GB2312"%%26gt;%26lt;form action£½"b.jsp"%26gt; name£º%26lt;input type£½text name£½name%26gt; %26lt;input type£½submit%26gt;%26lt;/form%26gt;
b.jspÒ³ÃæÄÚÈÝ£º
%26lt;%@ page language£½"java" import£½"java.util." pageE ......
JSPÓï·¨Ïê½â[תÌû]
HTML×¢ÊÍ:
1) ¿ÉÒÔÓÃ×¢ÊÍÄÚÈÝ,Ò²¿ÉÒÔÓñí´ïʽ.
2)Òþ²Ø×¢ÊÍ:
×¢Êͻᱠ......
̽Ë÷Èí¼þ¹¤×÷ÊÒ³¤ÆÚרҵ³Ð½ÓÖÐСÐÍÉÌÒµÈí¼þ»òÍøÕ¾£¬×îÓŻݵļ۸ñºÍ¸ßÖÊÁ¿µÄ·þÎñÆÚ´ýÄúµÄ»Ý¹Ë£¡
±¾¹¤×÷ÊÒ³Ð½Ó JSP ASP VB PB LotusNotes µÈÓïÑÔÒªÇóµÄÓ¦ÓÃϵͳ¿ª·¢ÒµÎñ
java jspʵսԴ³ÌÐò´úÂë:
......