Java]JAVA»ñÈ¡Ïà¶Ô·¾¶ÎÊÌâµÄ½â¾ö
(ת£ºhttp://blog.csdn.net/alex197963/archive/2008/03/26/2219994.aspx)
1.»ù±¾¸ÅÄîµÄÀí½â
¡¡¡¡¾ø¶Ô·¾¶:¾ø¶Ô·¾¶¾ÍÊÇÄãµÄÖ÷Ò³ÉϵÄÎļþ»òĿ¼ÔÚÓ²ÅÌÉÏÕæÕýµÄ·¾¶,(URLºÍÎïÀí·¾¶)ÀýÈç:
C:xyz est.txt ´ú±íÁËtest.txtÎļþµÄ¾ø¶Ô·¾¶.http://www.sun.com/index.htmÒ²´ú±íÁËÒ»¸ö
URL¾ø¶Ô·¾¶.
¡¡¡¡Ïà¶Ô·¾¶:Ïà¶ÔÓëij¸ö»ù׼Ŀ¼µÄ·¾¶.°üº¬WebµÄÏà¶Ô·¾¶(HTMLÖеÄÏà¶ÔĿ¼),ÀýÈç:ÔÚ
ServletÖÐ,"/"´ú±íWebÓ¦ÓõĸúĿ¼.ºÍÎïÀí·¾¶µÄÏà¶Ô±íʾ.ÀýÈç:"./" ´ú±íµ±Ç°Ä¿Â¼,
"../"´ú±íÉϼ¶Ä¿Â¼.ÕâÖÖÀàËƵıíʾ,Ò²ÊÇÊôÓÚÏà¶Ô·¾¶.
ÁíÍâ¹ØÓÚURI,URL,URNµÈÄÚÈÝ,Çë²Î¿¼RFCÏà¹ØÎĵµ±ê×¼.
RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax,(http://www.ietf.org/rfc/rfc2396.txt)
2.¹ØÓÚJSP/ServletÖеÄÏà¶Ô·¾¶ºÍ¾ø¶Ô·¾¶.
2.1·þÎñÆ÷¶ËµÄµØÖ·
¡¡¡¡ ·þÎñÆ÷¶ËµÄÏà¶ÔµØÖ·Ö¸µÄÊÇÏà¶ÔÓÚÄãµÄwebÓ¦ÓõĵØÖ·,Õâ¸öµØÖ·ÊÇÔÚ·þÎñÆ÷¶Ë½âÎöµÄ
(²»Í¬ÓÚhtmlºÍjavascriptÖеÄÏà¶ÔµØÖ·,ËûÃÇÊÇÓÉ¿Í»§¶Ëä¯ÀÀÆ÷½âÎöµÄ)Ò²¾ÍÊÇ˵Õâʱºò
ÔÚjspºÍservletÖеÄÏà¶ÔµØÖ·Ó¦¸ÃÊÇÏà¶ÔÓÚÄãµÄwebÓ¦ÓÃ,¼´Ïà¶ÔÓÚhttp://localhost/webapp/µÄ.
ÆäÓõ½µÄµØ·½ÓÐ:
forward:servletÖеÄrequest.getRequestDispatcher(address); Õâ¸öaddressÊÇ
ÔÚ·þÎñÆ÷¶Ë½âÎöµÄ,ËùÒÔ,ÄãÒªforwardµ½a.jspÓ¦¸ÃÕâôд:
request.getRequestDispatcher("/user/a.jsp")Õâ¸ö/Ïà¶ÔÓÚµ±Ç°µÄwebÓ¦ÓÃwebapp,
Æä¾ø¶ÔµØÖ·¾ÍÊÇ:http://localhost/webapp/user/a.jsp.
sendRedirect:ÔÚjspÖм´¿ÉÒÔдhttp://localhost/test.jsp Ò²¿ÉÒÔдÏà¶Ô·¾¶µ«URLÏÔʾ·¢ÉúÌøת
2.22,¿Í»§¶ËµÄµØÖ·
ËùÓеÄhtmlÒ³ÃæÖеÄÏà¶ÔµØÖ·¶¼ÊÇÏà¶ÔÓÚ·þÎñÆ÷¸ùĿ¼(http://localhost/)µÄ,
¶ø²»ÊÇ(¸úĿ¼ÏµĸÃWebÓ¦ÓõÄĿ¼)http://localhost/webapp/µÄ.
HtmlÖеÄform±íµ¥µÄactionÊôÐԵĵØÖ·Ó¦¸ÃÊÇÏà¶ÔÓÚ·þÎñÆ÷¸ùĿ¼(http://localhost/)µÄ,
ËùÒÔ,Èç¹ûÌá½»µ½a.jspΪ:action£½"/webapp/user/a.jsp"»òaction="/user/a.jsp;
¡¡¡¡Ìá½»µ½servletΪactiom£½"/webapp/handleservlet"
¡¡¡¡JavascriptÒ²ÊÇÔÚ¿Í»§¶Ë½âÎöµÄ,ËùÒÔÆäÏà¶Ô·¾¶ºÍform±íµ¥Ò»Ñù.
¡¡¡¡Òò´Ë,Ò»°ãÇé¿öÏÂ,ÔÚJSP/HTMLÒ³ÃæµÈÒýÓõÄCSS,Javascript.ActionµÈÊôÐÔÇ°Ãæ×îºÃ¶¼¼ÓÉÏ
,ÒÔÈ·±£ËùÒýÓõÄÎļþ¶¼ÊôÓÚWebÓ¦ÓÃÖеÄĿ¼.
ÁíÍâ,Ó¦¸Ã¾¡Á¿±ÜÃâʹÓÃÀàËÆ".","./","../../"µÈÀàËƵÄÏà¶Ô¸ÃÎļþλÖõÄÏà¶Ô·¾¶,ÕâÑù
µ±ÎļþÒƶ¯Ê±,ºÜÈÝÒ׳öÎÊÌâ.
3. JSP/ServletÖлñµÃ
Ïà¹ØÎĵµ£º
try {
String source = "xxx.xls";
InputStream is = new FileInputStream(source);
Workbook rwb = Workbook.getWorkbook(is);
Sheet sheet = rwb.getSheet(0);
for (int i = 1; i < sheet.getRows(); i++) {
for (int j = 1; j < sheet.getColumns(); j++) {
//»ñÈ¡Ö¸¶¨µ¥Ôª¸ñ ......
ÔÚJava
ÓïÑÔÖУ¬ abstract class ºÍinterface
ÊÇÖ§³Ö³éÏóÀà
¶¨
ÒåµÄÁ½ÖÖ»úÖÆ¡£ÕýÊÇÓÉÓÚÕâÁ½ÖÖ»úÖƵĴæÔÚ£¬²Å¸³ÓèÁËJavaÇ¿´óµÄ ÃæÏò¶ÔÏóÄÜÁ¦¡£abstract
classºÍinterfaceÖ®¼äÔÚ¶ÔÓÚ³éÏóÀඨÒåµÄÖ§³Ö·½Ãæ¾ßÓкܴóµÄÏàËÆÐÔ£¬ÉõÖÁ¿ÉÒÔÏ໥Ìæ»»£¬Òò´ËºÜ¶à¿ª·¢ÕßÔÚ½ø
ÐгéÏóÀඨÒåʱ¶ÔÓÚabstract
classºÍinterfaceµÄÑ¡Ô ......
ËäÈ»Óà Java™ ÓïÑÔ±àдµÄ³ÌÐòÔÚÀíÂÛÉÏÊDz»»á³öÏÖ“ÄÚ´æй©”µÄ£¬µ«ÊÇÓÐʱ¶ÔÏóÔÚ²»ÔÙ×÷Ϊ³ÌÐòµÄÂ߼״̬µÄÒ»²¿·ÖÖ®ºóÈÔÈ»²»±»À¬»øÊÕ¼¯¡£±¾Ô£¬¸ºÔð±£ÕÏÓ¦ÓóÌÐò½¡¿µµÄ¹¤³Ìʦ Brian Goetz ̽ÌÖÁËÎÞÒâʶµÄ¶ÔÏó±£ÁôµÄ³£¼ûÔÒò£¬²¢Õ¹Ê¾ÁËÈçºÎÓÃÈõÒýÓöÂסй©¡£
ÒªÈÃÀ¬»øÊÕ¼¯£¨GC£©»ØÊÕ³ÌÐò²»ÔÙʹÓõĶÔÏ󣬶 ......
import java.io.*;
public class CheckVirusFile
{
int virusCount=0,del_count=0,spe_count=0,nameCount=0;
//ÓõݹéµÄ·½·¨¼ì²éFileÀàÐ͵IJÎÊýÊÇÎļþ»¹ÊÇĿ¼
public void judgeDir(File virFile)
{
if(!virFile.isDir ......