- 浏览: 1228477 次
博客专栏
-
SQL Server 20...
浏览量:18940
文章分类
最新评论
-
120153216:
我这是一直点击Table标签,最后点提交就变成这样了..你删掉 ...
JSP静态化 -
as1245:
<a href="http://www.bai ...
JSP静态化 -
120153216:
...
JSP静态化 -
crazyjixiang:
http://blog.csdn.net/crazyjixia ...
Vim 半透明化. -
crazyjixiang:
转载需要请写下 转载地址http://blog.csdn.ne ...
Vim 半透明化.
java安全机制其实有点不安全
看下面的这段代码,摘自《Java Examples in a Nutsbell》(java实例技术手册):
就是一个简单的通用的多线程服务器
这个例子可以通过配置参数:
java je3.net.Server -control www 3333 je3.net.Server$HTTPMirror 5555
来启动,然后再ie中输入: http://localhost:5555就可以看到效果。
写一个policy文件放在同根目录下:叫server.policy
grant{
permission java.net.SocketPermission "*:1024-4444","connect,accept";
permission java.io.FilePermission "E://workspace//j2ee1.3//-", "read";
};
下面加上jvm虚拟机参数
java -Djava.security.manager -Djava.security.policy=server.policy
je3.net.Server -control www 3333 je3.net.Server$HTTPMirror 5555再次启动。
按道理,本不应该启动。因为端口5555并没有得到连接许可。但是很可惜输入 http://localhost:5555还是可以看到结果。因为在java的sdk中暗含了java.policy文件。那就把它改为-Djava.security.policy==server.policy应该就可以了。结果跑不了了。原因就在policy文件中的permission java.net.SocketPermission "*:1024-4444","connect,accept";其实,我一直不太清楚listen ,accept,connect的区别在什么地方。但是这里的例子说明你只用permission java.net.SocketPermission "*:1024-4444","listen";就可以了。端口该闭的就闭了。如果用accept和connect反而没有什么用。不知道java的安全性高在什么地方。因为java.policy文件中从1024以上的端口全都使用了listen。所以以后要配置端口时一定要注意。
*Copyright(c)2004DavidFlanagan.Allrightsreserved.
*ThiscodeisfromthebookJavaExamplesinaNutshell,3ndEdition.
*ItisprovidedAS-IS,WITHOUTANYWARRANTYeitherexpressedorimplied.
*Youmaystudy,use,andmodifyitforanynon-commercialpurpose,
*includingteachinganduseinopen-sourceprojects.
*Youmaydistributeitnon-commerciallyaslongasyouretainthisnotice.
*Foracommercialuselicense,ortopurchasethebook,
*pleasevisithttp://www.davidflanagan.com/javaexamples3.
*/
packageje3.net;
importjava.io.*;
importjava.net.*;
importjava.util.*;
importjava.util.logging.*;
/***//**
*Thisclassisagenericframeworkforaflexible,multi-threadedserver.
*Itlistensonanynumberofspecifiedports,and,whenitreceivesa
*connectiononaport,passesinputandoutputstreamstoaspecifiedService
*objectwhichprovidestheactualservice.Itcanlimitthenumberof
*concurrentconnections,andlogsactivitytoaspecifiedstream.
**/
publicclassServer...{
/***//**
*Amain()methodforrunningtheserverasastandaloneprogram.The
*command-lineargumentstotheprogramshouldbepairsofservicenames
*andportnumbers.Foreachpair,theprogramwilldynamicallyloadthe
*namedServiceclass,instantiateit,andtelltheservertoprovide
*thatServiceonthespecifiedport.Thespecial-controlargument
*shouldbefollowedbyapasswordandport,andwillstartspecial
*servercontrolservicerunningonthespecifiedport,protectedbythe
*specifiedpassword.
**/
publicstaticvoidmain(String[]args)...{
try...{
if(args.length<2)//Checknumberofarguments
thrownewIllegalArgumentException("Mustspecifyaservice");
//Createaserverobjectthathasalimitof10concurrent
//connections,andlogstoaLoggerattheLevel.INFOlevel
//PriortoJava1.4wedidthis:newServer(System.out,10);
Servers=newServer(Logger.getLogger(Server.class.getName()),
Level.INFO,10);
//Parsetheargumentlist
inti=0;
while(i<args.length)...{
if(args[i].equals("-control"))...{//Handlethe-controlarg
i++;
Stringpassword=args[i++];
intport=Integer.parseInt(args[i++]);
//addcontrolservice
s.addService(newControl(s,password),port);
}
else...{
//Otherwisestartanamedserviceonthespecifiedport.
//DynamicallyloadandinstantiateaServiceclass
StringserviceName=args[i++];
ClassserviceClass=Class.forName(serviceName);
Serviceservice=(Service)serviceClass.newInstance();
intport=Integer.parseInt(args[i++]);
s.addService(service,port);
}
}
}
catch(Exceptione)...{//Displayamessageifanythinggoeswrong
System.err.println("Server:"+e);
System.err.println("Usage:javaServer"+
"[-control<password><port>]"+
"[<servicename><port>...]");
System.exit(1);
}
}
//Thisisthestatefortheserver
Mapservices;//HashtablemappingportstoListeners
Setconnections;//Thesetofcurrentconnections
intmaxConnections;//Theconcurrentconnectionlimit
ThreadGroupthreadGroup;//Thethreadgroupforallourthreads
//Thisclasswasoriginallywrittentosendloggingoutputtoastream.
//Ithasbeenretrofittedtoalsosupportthejava.util.loggingAPIof
//Java1.4.Youcanuseeither,neither,orboth.
PrintWriterlogStream;//Wherewesendourloggingoutputto
Loggerlogger;//AJava1.4loggingdestination
LevellogLevel;//theleveltologmessagesat
/***//**
*ThisistheServer()constructor.Itmustbepassedastream
*tosendlogoutputto(maybenull),andthelimitonthenumberof
*concurrentconnections.
**/
publicServer(OutputStreamlogStream,intmaxConnections)...{
this(maxConnections);
setLogStream(logStream);
log("Startingserver");
}
/***//**
*ThisconstructoraddedtosupportloggingwiththeJava1.4Loggerclass
**/
publicServer(Loggerlogger,LevellogLevel,intmaxConnections)...{
this(maxConnections);
setLogger(logger,logLevel);
log("Startingserver");
}
/***//**
*Thisconstructorsupportsnologging
**/
publicServer(intmaxConnections)...{
threadGroup=newThreadGroup(Server.class.getName());
this.maxConnections=maxConnections;
services=newHashMap();
connections=newHashSet(maxConnections);
}
/***//**
*Apublicmethodtosetthecurrentloggingstream.Passnull
*toturnloggingoff.
**/
publicsynchronizedvoidsetLogStream(OutputStreamout)...{
if(out!=null)logStream=newPrintWriter(out);
elselogStream=null;
}
/***//**
*SetthecurrentLoggerandlogginglevel.Passnulltoturnloggingoff.
**/
publicsynchronizedvoidsetLogger(Loggerlogger,Levellevel)...{
this.logger=logger;
this.logLevel=level;
}
/***//**Writethespecifiedstringtothelog*/
protectedsynchronizedvoidlog(Strings)...{
if(logger!=null)logger.log(logLevel,s);
if(logStream!=null)...{
logStream.println("["+newDate()+"]"+s);
logStream.flush();
}
}
/***//**Writethespecifiedobjecttothelog*/
protectedvoidlog(Objecto)...{log(o.toString());}
/***//**
*Thismethodmakestheserverstartprovidinganewservice.
*ItrunsthespecifiedServiceobjectonthespecifiedport.
**/
publicsynchronizedvoidaddService(Serviceservice,intport)
throwsIOException
...{
Integerkey=newInteger(port);//thehashtablekey
//Checkwhetheraserviceisalreadyonthatport
if(services.get(key)!=null)
thrownewIllegalArgumentException("Port"+port+
"alreadyinuse.");
//CreateaListenerobjecttolistenforconnectionsontheport
Listenerlistener=newListener(threadGroup,port,service);
//Storeitinthehashtable
services.put(key,listener);
//Logit
log("Startingservice"+service.getClass().getName()+
"onport"+port);
//Startthelistenerrunning.
listener.start();
}
/***//**
*Thismethodmakestheserverstopprovidingaserviceonaport.
*Itdoesnotterminateanypendingconnectionstothatservice,merely
*causestheservertostopacceptingnewconnections
**/
publicsynchronizedvoidremoveService(intport)...{
Integerkey=newInteger(port);//hashtablekey
//LookuptheListenerobjectfortheportinthehashtable
finalListenerlistener=(Listener)services.get(key);
if(listener==null)return;
//Askthelistenertostop
listener.pleaseStop();
//Removeitfromthehashtable
services.remove(key);
//Andlogit.
log("Stoppingservice"+listener.service.getClass().getName()+
"onport"+port);
}
/***//**
*ThisnestedThreadsubclassisa"listener".Itlistensfor
*connectionsonaspecifiedport(usingaServerSocket)andwhenitgets
*aconnectionrequest,itcallstheserversaddConnection()methodto
*accept(orreject)theconnection.ThereisoneListenerforeach
*ServicebeingprovidedbytheServer.
**/
publicclassListenerextendsThread...{
ServerSocketlisten_socket;//Thesockettolistenforconnections
intport;//Theportwe'relisteningon
Serviceservice;//Theservicetoprovideonthatport
volatilebooleanstop=false;//Whetherwe'vebeenaskedtostop
/***//**
*TheListenerconstructorcreatesathreadforitselfinthe
*threadgroup.ItcreatesaServerSockettolistenforconnections
*onthespecifiedport.ItarrangesfortheServerSockettobe
*interruptible,sothatservicescanberemovedfromtheserver.
**/
publicListener(ThreadGroupgroup,intport,Serviceservice)
throwsIOException
...{
super(group,"Listener:"+port);
listen_socket=newServerSocket(port);
//giveitanon-zerotimeoutsoaccept()canbeinterrupted
listen_socket.setSoTimeout(5000);
this.port=port;
this.service=service;
}
/***//**
*ThisisthepolitewaytogetaListenertostopaccepting
*connections
***/
publicvoidpleaseStop()...{
this.stop=true;//Setthestopflag
this.interrupt();//Stopblockinginaccept()
try...{listen_socket.close();}//Stoplistening.
catch(IOExceptione)...{}
}
/***//**
*AListenerisaThread,andthisisitsbody.
*Waitforconnectionrequests,acceptthem,andpassthesocketon
*totheaddConnectionmethodoftheserver.
**/
publicvoidrun()...{
while(!stop)...{//loopuntilwe'reaskedtostop.
try...{
Socketclient=listen_socket.accept();
addConnection(client,service);
}
catch(InterruptedIOExceptione)...{}
catch(IOExceptione)...{log(e);}
}
}
}
/***//**
*ThisisthemethodthatListenerobjectscallwhentheyaccepta
*connectionfromaclient.IteithercreatesaConnectionobject
*fortheconnectionandaddsittothelistofcurrentconnections,
*or,ifthelimitonconnectionshasbeenreached,itclosesthe
*connection.
**/
protectedsynchronizedvoidaddConnection(Sockets,Serviceservice)...{
//Iftheconnectionlimithasbeenreached
if(connections.size()>=maxConnections)...{
try...{
//Thentelltheclientitisbeingrejected.
PrintWriterout=newPrintWriter(s.getOutputStream());
out.print("Connectionrefused;"+
"theserverisbusy;pleasetryagainlater. ");
out.flush();
//Andclosetheconnectiontotherejectedclient.
s.close();
//Andlogit,ofcourse
log("Connectionrefusedto"+
s.getInetAddress().getHostAddress()+
":"+s.getPort()+":maxconnectionsreached.");
}catch(IOExceptione)...{log(e);}
}
else...{//Otherwise,ifthelimithasnotbeenreached
//CreateaConnectionthreadtohandlethisconnection
Connectionc=newConnection(s,service);
//Addittothelistofcurrentconnections
connections.add(c);
//Logthisnewconnection
log("Connectedto"+s.getInetAddress().getHostAddress()+
":"+s.getPort()+"onport"+s.getLocalPort()+
"forservice"+service.getClass().getName());
//AndstarttheConnectionthreadtoprovidetheservice
c.start();
}
}
/***//**
*AConnectionthreadcallsthismethodjustbeforeitexits.Itremoves
*thespecifiedConnectionfromthesetofconnections.
**/
protectedsynchronizedvoidendConnection(Connectionc)...{
connections.remove(c);
log("Connectionto"+c.client.getInetAddress().getHostAddress()+
":"+c.client.getPort()+"closed.");
}
/***//**Changethecurrentconnectionlimit*/
publicsynchronizedvoidsetMaxConnections(intmax)...{
maxConnections=max;
}
/***//**
*Thismethoddisplaysstatusinformationabouttheserveronthe
*specifiedstream.Itcanbeusedfordebugging,andisusedbythe
*Controlservicelaterinthisexample.
**/
publicsynchronizedvoiddisplayStatus(PrintWriterout)...{
//DisplayalistofallServicesthatarebeingprovided
Iteratorkeys=services.keySet().iterator();
while(keys.hasNext())...{
Integerport=(Integer)keys.next();
Listenerlistener=(Listener)services.get(port);
out.print("SERVICE"+listener.service.getClass().getName()
+"ONPORT"+port+" ");
}
//Displaythecurrentconnectionlimit
out.print("MAXCONNECTIONS:"+maxConnections+" ");
//Displayalistofallcurrentconnections
Iteratorconns=connections.iterator();
while(conns.hasNext())...{
Connectionc=(Connection)conns.next();
out.print("CONNECTEDTO"+
c.client.getInetAddress().getHostAddress()+
":"+c.client.getPort()+"ONPORT"+
c.client.getLocalPort()+"FORSERVICE"+
c.service.getClass().getName()+" ");
}
}
/***//**
*ThisclassisasubclassofThreadthathandlesanindividual
*connectionbetweenaclientandaServiceprovidedbythisserver.
*Becauseeachsuchconnectionhasathreadofitsown,eachServicecan
*havemultipleconnectionspendingatonce.Despitealltheother
*threadsinuse,thisisthekeyfeaturethatmakesthisa
*multi-threadedserverimplementation.
**/
publicclassConnectionextendsThread...{
Socketclient;//Thesockettotalktotheclientthrough
Serviceservice;//Theservicebeingprovidedtothatclient
/***//**
*Thisconstructorjustsavessomestateandcallsthesuperclass
*constructortocreateathreadtohandletheconnection.Connection
*objectsarecreatedbyListenerthreads.Thesethreadsarepartof
*theserver'sThreadGroup,soallConnectionthreadsarepartofthat
*group,too.
**/
publicConnection(Socketclient,Serviceservice)...{
super("Server.Connection:"+
client.getInetAddress().getHostAddress()+
":"+client.getPort());
this.client=client;
this.service=service;
}
/***//**
*ThisisthebodyofeachandeveryConnectionthread.
*Allitdoesispasstheclientinputandoutputstreamstothe
*serve()methodofthespecifiedServiceobject.Thatmethodis
*responsibleforreadingfromandwritingtothosestreamsto
*providetheactualservice.RecallthattheServiceobjecthas
*beenpassedfromtheServer.addService()methodtoaListener
*objecttotheaddConnection()methodtothisConnectionobject,and
*isnowfinallybeingusedtoprovidetheservice.Notethatjust
*beforethisthreadexitsitalwayscallstheendConnection()method
*toremoveitselffromthesetofconnections
**/
publicvoidrun()...{
try...{
InputStreamin=client.getInputStream();
OutputStreamout=client.getOutputStream();
service.serve(in,out);
}
catch(IOExceptione)...{log(e);}
finally...{endConnection(this);}
}
}
/***//**
*HereistheServiceinterfacethatwehaveseensomuchof.Itdefines
*onlyasinglemethodwhichisinvokedtoprovidetheservice.serve()
*willbepassedaninputstreamandanoutputstreamtotheclient.It
*shoulddowhateveritwantswiththem,andshouldclosethembefore
*returning.
*
*Allconnectionsthroughthesameporttothisserviceshareasingle
*Serviceobject.Thus,anystatelocaltoanindividualconnectionmust
*bestoredinlocalvariableswithintheserve()method.Statethat
*shouldbeglobaltoallconnectionsonthesameportshouldbestored
*ininstancevariablesoftheServiceclass.IfthesameServiceis
*runningonmorethanoneport,therewilltypicallybedifferent
*Serviceinstancesforeachport.Datathatshouldbeglobaltoall
*connectionsonanyportshouldbestoredinstaticvariables.
*
*Notethatimplementationsofthisinterfacemusthaveano-argument
*constructoriftheyaretobedynamicallyinstantiatedbythemain()
*methodoftheServerclass.
**/
publicinterfaceService...{
publicvoidserve(InputStreamin,OutputStreamout)throwsIOException;
}
/***//**
*Averysimpleservice.Itdisplaysthecurrenttimeontheserver
*totheclient,andclosestheconnection.
**/
publicstaticclassTimeimplementsService...{
publicvoidserve(InputStreami,OutputStreamo)throwsIOException...{
PrintWriterout=newPrintWriter(o);
out.print(newDate()+" ");
out.close();
i.close();
}
}
/***//**
*Thisisanotherexampleservice.Itreadslinesofinputfromthe
*client,andsendsthemback,reversed.Italsodisplaysawelcome
*messageandinstructions,andclosestheconnectionwhentheuser
*entersa'.'onalinebyitself.
**/
publicstaticclassReverseimplementsService...{
publicvoidserve(InputStreami,OutputStreamo)throwsIOException...{
BufferedReaderin=newBufferedReader(newInputStreamReader(i));
PrintWriterout=
newPrintWriter(newBufferedWriter(newOutputStreamWriter(o)));
out.print("Welcometothelinereversalserver. ");
out.print("Enterlines.Endwitha'.'onalinebyitself. ");
for(;;)...{
out.print(">");
out.flush();
Stringline=in.readLine();
if((line==null)||line.equals("."))break;
for(intj=line.length()-1;j>=0;j--)
out.print(line.charAt(j));
out.print(" ");
}
out.close();
in.close();
}
}
/***//**
*ThisserviceisanHTTPmirror,justliketheHttpMirrorclass
*implementedearlierinthischapter.Itechosbacktheclient's
*HTTPrequest
**/
publicstaticclassHTTPMirrorimplementsService...{
publicvoidserve(InputStreami,OutputStreamo)throwsIOException...{
BufferedReaderin=newBufferedReader(newInputStreamReader(i));
PrintWriterout=newPrintWriter(o);
out.print("HTTP/1.0200 ");
out.print("Content-Type:text/plain ");
Stringline;
while((line=in.readLine())!=null)...{
if(line.length()==0)break;
out.print(line+" ");
}
out.close();
in.close();
}
}
/***//**
*Thisservicedemonstrateshowtomaintainstateacrossconnectionsby
*savingitininstancevariablesandusingsynchronizedaccesstothose
*variables.Itmaintainsacountofhowmanyclientshaveconnectedand
*tellseachclientwhatnumberitis
**/
publicstaticclassUniqueIDimplementsService...{
publicintid=0;
publicsynchronizedintnextId()...{returnid++;}
publicvoidserve(InputStreami,OutputStreamo)throwsIOException...{
PrintWriterout=newPrintWriter(o);
out.print("Youareclient#:"+nextId()+" ");
out.close();
i.close();
}
}
/***//**
*Thisisanon-trivialservice.Itimplementsacommand-basedprotocol
*thatgivespassword-protectedruntimecontrolovertheoperationofthe
*server.Seethemain()methodoftheServerclasstoseehowthis
*serviceisstarted.
*
*Therecognizedcommandsare:
*password:givepassword;authorizationisrequiredformostcommands
*add:dynamicallyaddanamedserviceonaspecifiedport
*remove:dynamicallyremovetheservicerunningonaspecifiedport
*max:changethecurrentmaximumconnectionlimit.
*status:displaycurrentservices,connections,andconnectionlimit
*help:displayahelpmessage
*quit:disconnect
*
*Thisservicedisplaysaprompt,andsendsallofitsoutputtotheuser
*incapitalletters.Onlyoneclientisallowedtoconnecttothis
*serviceatatime.
**/
publicstaticclassControlimplementsService...{
Serverserver;//Theserverwecontrol
Stringpassword;//Thepasswordwerequire
booleanconnected=false;//Whetheraclientisalreadyconnected
/***//**
*CreateanewControlservice.ItwillcontrolthespecifiedServer
*object,andwillrequirethespecifiedpasswordforauthorization
*NotethatthisServicedoesnothaveanoargumentconstructor,
*whichmeansthatitcannotbedynamicallyinstantiatedandaddedas
*theother,genericservicesabovecanbe.
**/
publicControl(Serverserver,Stringpassword)...{
this.server=server;
this.password=password;
}
/***//**
*Thisistheservemethodthatprovidestheservice.Itreadsa
*linetheclient,andusesjava.util.StringTokenizertoparseit
*intocommandsandarguments.Itdoesvariousthingsdependingon
*thecommand.
**/
publicvoidserve(InputStreami,OutputStreamo)throwsIOException...{
//Setupthestreams
BufferedReaderin=newBufferedReader(newInputStreamReader(i));
PrintWriterout=newPrintWriter(o);
Stringline;//Forreadingclientinputlines
//Hastheuserhasgiventhepasswordyet?
booleanauthorized=false;
//Ifthereisalreadyaclientconnectedtothisservice,display
//amessagetothisclientandclosetheconnection.Weusea
//synchronizedblocktopreventaracecondition.
synchronized(this)...{
if(connected)...{
out.print("ONLYONECONTROLCONNECTIONALLOWED. ");
out.close();
return;
}
elseconnected=true;
}
//Thisisthemainloop:readacommand,parseit,andhandleit
for(;;)...{//infiniteloop
out.print(">");//Displayaprompt
out.flush();//Makeitappearrightaway
line=in.readLine();//Gettheuser'sinput
if(line==null)break;//QuitifwegetEOF.
try...{
//UseaStringTokenizertoparsetheuser'scommand
StringTokenizert=newStringTokenizer(line);
if(!t.hasMoreTokens())continue;//ifinputwasempty
//Getfirstwordoftheinputandconverttolowercase
Stringcommand=t.nextToken().toLowerCase();
//Nowcomparetoeachofthepossiblecommands,doingthe
//appropriatethingforeachcommand
if(command.equals("password"))...{//Passwordcommand
Stringp=t.nextToken();//Getthenextword
if(p.equals(this.password))...{//Isitthepassword?
out.print("OK ");//Sayso
authorized=true;//Grantauthorization
}
elseout.print("INVALIDPASSWORD ");
}
elseif(command.equals("add"))...{//AddServicecommand
//Checkwhetherpasswordhasbeengiven
if(!authorized)out.print("PASSWORDREQUIRED ");
else...{
//Getthenameoftheserviceandtryto
//dynamicallyloadandinstantiateit.
//Exceptionswillbehandledbelow
StringserviceName=t.nextToken();
ClassserviceClass=Class.forName(serviceName);
Serviceservice;
try...{
service=(Service)serviceClass.newInstance();
}
catch(NoSuchMethodErrore)...{
thrownewIllegalArgumentException(
"Servicemusthavea"+
"no-argumentconstructor");
}
intport=Integer.parseInt(t.nextToken());
//Ifnoexceptionsoccurred,addtheservice
server.addService(service,port);
out.print("SERVICEADDED ");//acknowledge
}
}
elseif(command.equals("remove"))...{//Removeservice
if(!authorized)out.print("PASSWORDREQUIRED ");
else...{
intport=Integer.parseInt(t.nextToken());
server.removeService(port);//removetheservice
out.print("SERVICEREMOVED ");//acknowledge
}
}
elseif(command.equals("max"))...{//Setconnectionlimit
if(!authorized)out.print("PASSWORDREQUIRED ");
else...{
intmax=Integer.parseInt(t.nextToken());
server.setMaxConnections(max);
out.print("MAXCONNECTIONSCHANGED ");
}
}
elseif(command.equals("status"))...{//StatusDisplay
if(!authorized)out.print("PASSWORDREQUIRED ");
elseserver.displayStatus(out);
}
elseif(command.equals("help"))...{//Helpcommand
//Displaycommandsyntax.Passwordnotrequired
out.print("COMMANDS: "+
" password<password> "+
" add<service><port> "+
" remove<port> "+
" max<max-connections> "+
" status "+
" help "+
" quit ");
}
elseif(command.equals("quit"))break;//Quitcommand.
elseout.print("UNRECOGNIZEDCOMMAND ");//Error
}
catch(Exceptione)...{
//Ifanexceptionoccurredduringthecommand,printan
//errormessage,thenoutputdetailsoftheexception.
out.print("ERRORWHILEPARSINGOREXECUTINGCOMMAND: "+
e+" ");
}
}
//Finally,whentheloopcommandloopends,closethestreams
//andsetourconnectedflagtofalsesothatotherclientscan
//nowconnect.
connected=false;
out.close();
in.close();
}
}
}
相关推荐
Java 3DMenu 界面源码,有人说用到游戏中不错,其实平时我信编写Java应用程序时候也能用到吧,不一定非要局限于游戏吧,RES、SRC资源都有,都在压缩包内。 Java zip压缩包查看程序源码 1个目标文件 摘要:Java源码...
Java 3DMenu 界面源码,有人说用到游戏中不错,其实平时我信编写Java应用程序时候也能用到吧,不一定非要局限于游戏吧,RES、SRC资源都有,都在压缩包内。 Java zip压缩包查看程序源码 1个目标文件 摘要:Java源码...
JAVA学习要点 一、关于Java ...多态性就是“一种接口,多种方法”,可以为一组相关的动作设计一个通用的接口,其实类的函数的重载就是一种多态的体现; 4 引入抽象编程的思想; 类的封装就是一种抽象思想
一、Java基础知识 1.Java有那些基本数据类型,String是不是基本数据类型,他们有何区别。 2.字符串的操作: 写一个方法,实现字符串的反转,如:输入abc,输出cba 写一个方法,实现字符串的替换,如:输入...
java.lang.String类是final类型的,因此不可以继承这个类、不能修改这个类。为了提高效率节省空间,我们应该用StringBuffer类 3、int 和 Integer 有什么区别 Java 提供两种不同的类型:引用类型和原始类型(或内置...
java.lang.String类是final类型的,因此不可以继承这个类、不能修改这个类。为了提高效率节省空间,我们应该用StringBuffer类 6、int 和 Integer 有什么区别 Java 提供两种不同的类型:引用类型和原始类型(或...
本程序是支持线程安全的java群体聊天室,其实在消息传送过程中均采用了网络安全的加密机制。
当真正理解了,其实也就不难了。先举例子来理解什么是反射。 先建这样的一个类,带会下面有个类里面有反射成员变量的方法的! public class ReflectPoint { private int x; public int y; public ReflectPoint...
答:Servlet与CGI的区别在于Servlet处于服务器进程中,它通过多线程方式允许其service方法,一个实例可以服务于多个请求,并且其实例一般不会被销毁,而CGI对每个请求都产生新的进程,服务完后就销毁,所以效率上...
技术上采用sun公司的java语言,该语言有很多有点,比如多线程、网络流概念、异常捕获处理、安全性以及速度与性能等方面,并且具有可以一次编写、到处运行的跨平台优点。 多线程:多线程是这样一种机制,它允许在程序...
jdk1.5版本以后出现的新特性,用于解决安全问题,是一个安全机制。 好处: 1,将运行时期的问题ClassCastException转到了编译时期。 2,避免了强制转换的麻烦。 什么时候用: 当操作的引用数据...
小按:第一次写心得笔记,手都有点抖,班门弄斧啊,...基本上是一个总结或者说是“读后感”的性质,同时给出一个简单的实现例子,这个例子其实还是模仿人家的,呵呵……1.Java的访问控制机制 谈到访问控制,或者说
从Jdk6.0以后要求,JDBC 4.0 Drivers 必须包括 META-INF/services/java.sql.Driver 文件,有了这个文件以后不需要在显示的使用Class.forName来进行驱动的注册 Oracle数据库进行连接的时候,使用的驱动类: 1....
其实,这个错误并不一定是Windows不稳定造成的。本文就来简单分析这种错误的一般原因。 一、应用程序没有检查内存分配失败 程序需要一块内存用以储存数据时,就需要使用操作系统提供的「功能函数」来申请,如果内存...
在过去十年,基于Java的MVC框架如同雨后春笋一般层出不穷,但都不愿意面对或者解决的问题是,它对前端设计师极不友好,而且,开发效率及其低下,互联网企业鲜有基于Java,尤其是基于MVC来构建自己的网站,是有深刻的...
这有点向java中的import语句,多数类在使用之前需要引入,但引入了类并不意味着这些在使用,每个creator和converter需要有个id属性来允许以后进行引用. 配置文件的allow部分定义哪些类可以建立和转换,每个被准许的类都...
从数据安全角度考虑,考虑动态数据与网站数据库分开存储,同时把动态数据展现界 面也单独部署,与对外网站建立链接,形成主站与子站的关系,可以利用公司现有网络 安全控制机制很好地保护动态数据的安全性。...
� Google 提供了一套 Java 核心包 (J2SE 5,J2SE 6) 的有限子集,尚不承诺遵守 Java 任何 Java 规范 , 可能会造 成J ava 阵营的进一步分裂。 � 现有应用完善度不太够,需要的开发工作量较大。--------------------...