|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
其实产生见解的过程就是训练自己发现问题,分析问题的能力。根据以上的认识我想谈下传统的学习与通过视频独立学习的优缺点:js18)Whatdothedifferinglevelsofbeanstorage(page,session,app)mean?TOC
From:JoeShevland<J_Shevland@TurnAround.com.au>
ThespecisnotclearonwhattheApplicationlevelscopeactuallymeans,butthegeneraldiscussionhasitthatanApplicationisasingleJSPwhosebeanspersistfromcalltocall-unlikethosebeanswhichhavethe"page"scope.Thatsaid,the0.92specstillstores"application"beansattheservletlevelsotheycanactuallybeusedbymultipleservlets.
(FromGabrielWong<gabrielw@EZWEBTOOLS.COM>)
InpurelyServletterms,theymean:
page-NOstorage
session-servletrequest.getSession(true).putValue("myobjectname",myobject);
application-getServletConfig().getServletContext().setAttribute("myobjectname",myobject);
request-Thestorageexistsforthelifetimeoftherequest,whichmaybeforwardedbetweenjspsandservlets.
19)WherecanIfindthemailinglistarchives?TOC
ArchivesoftheJSPmailinglistareavailableathttp://archives.java.sun.com/archives/jsp-interest.html
Thesearchivesaresearchable.
20)WhataretheimportantstepsinusingJDBCinJSP?TOC
1)InstantiateaninstanceoftheJDBCdriveryouretryingtouse(jdbc-odbcbridgenamefrommemorysoplscheck):
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Thisdeterminesiftheclassisavailableandinstantiatesanewinstanceofit,makingitavailableforthenextstep.
2)AsktheDriverManagerforaConnectionobjectbasedontheJDBCURLyouareusing:
ConnectionconnDB=DriverManager.getConnection("jdbc:odbc:MyDSN",
"username","password");
DriverManagersearchesthroughanyregistereddrivers(instantiatinganewinstanceaboveisenoughtoregisteradriverwiththeDriverManager,aseachimplementationisrequiredto)and,basedontheJDBCURLyouareusing,returnstheappropriateimplementationofConnection.
3)CreateaStatementobjecttoretrieveaResultSet
StatementsmentDB=connDB.createStatement();
ResultSetrsDB=connDB.executeQuery("SELECT*FROMFoo");
or
rsDB=connDB.executeUpdate("UPDATEFooSETBar=NULL");
4)Closedownconnectionstofreeresources:
rsDB.close();
smentDB.close();
connDB.close();
NotesmentDB.close()closesthersDBobject,andconnDBwillclosesmentDB,cascadingdown,soyoucanreallyjust:connDB.Close().Alsonotetheresnoexceptionhandlinggivenhere.
WiththereleaseoftheJDBC2.0API,thereisaCachedResultSetcapabilitywhichwouldprovidesomeassistanceinmakingyourpagesperformbetter:
From:DIGNEMarc<jmdigne@MEUDON.NETCABLE.TM.FR>
ItestedtheJDBCCachedRowSethttp://developer.java.sun.com/developer/earlyAccess/crs/index.html
"JDBCTMCachedRowSetisanimplementationoftheRowsetinterface.TheRowsetinterfaceispartoftheJDBC2.0StandardExtensionAPI.
CachedRowSetprovidesadisconnected,serializable,scrollablecontainerfortabulardata.ACachedRowSetobjectcanbethoughtofasadisconnectedsetofrowsthatarebeingcachedoutsideofadatasource.
DatacontainedinaCachedRowSetmaybeupdatedandthenresynchronizedwiththeunderlyingtabulardatasource."
21)HowdoesvariablescopeworkinJSP?TOC
From:AlexanderYavorskiy<Alexander_Yavorskiy@VANTIVE.COM>
Hi,
AninterestingobservationaboutthevariablesdeclaredinJSPpages.
Anyvariabledeclaredinside<%....%>islocaltothepageandisnotvisibletooutsidefunctions,eventhosedeclareonthesameJSP.
Example:
<%
intevilVariable="666";
%>
...
functiontestFunction(){
//donotseeevilVariablefromhere
}
Why?evilVariableeventuallybecomesalocalvariableintheservice()methodoftheresultingservletandsoisnotaccessiblebyothermethodsofthatservlet.
Anyvariabledeclaredinside<%!%>becomeglobalforanyfunctiondeclaredintheservlet.
Example:
<%!
intevilVariable="666";
%>
...
functiontestFunction(){
intx=evilVariable;//cangettoit
}
Why?evilVariabledeclaredthiswaybecomesaprivatemembervariableoftheresultingservletandsoisaccessiblebyallothermethodsofthatservlet.
Conclusion
Itisimportanttounderstandthisdifferencebecauseinservletenvironmenttherewillonlybeasingle(!!!)instanceoftheresultingservletrunningandservingallrequestsforaparticularpage.Thus,potentiallyallofthemembervariablesofthatservletwillbeshareacrosstherequestsasopposedtovariableslocaltotheservice()methodthatwillberecreatedforeachrequest.So,weshouldbecarefulaboutputtingnoneconstantvariablesin<SERVER></SERVER>.Atthesametime,itmightbeusefultodosoinsomesituations.
22)HowdoIforwardtoanHTMLpage?TOC
Themethodforward()intheServletAPIworksforJSPpages,butthisisonlytrueforresourceswith_active_content,likeJSPpages.
IfyouwishtoforwardtoanHTMLpage,youhavetouseadifferentmethod:
From:VolkerStiehl<stiehl@ZNNBG.SIEMENS.DE>
InordertoaccessHTMLfilesyouhavetousethenew"resourceabstraction"featureof2.1.
Trythefollowing:
URLurl=getServletContext().getResource("/abc/xyz.html");
out.println(url.getContent());
23)ArethereanywhitepapersordocumentsexplaininghowJSPfits?TOC
From:"CraigR.McClanahan"<cmcclanahan@mytownnet.com>
http://www.software.ibm.com/ebusiness/pm.html
Itistitled"TheWebApplicationProgrammingModel",andprovidesaniceoverviewofthebasicarchitectureIBMproposesforwebapplications(essentiallythe"Model2"approachfromtheJSPspecification).TherearefewIBM-specificproductreferencesinthisdocument--simplytranslatetheirterm"dynamicserverpages"intoJSP,andgeneralize"WebSphere"toanyusefulcombinationofwebserver,servletengine,andappservercomponents.TherearemoreIBM-specificreferencesinseveraloftheotherwhitepapers,buttheystillprovideausefuloverviewofthetechnologybasisforlargescaleweb-basedapplicationdevelopmentanddeployment.Thewhitepaperindexisat:
http://www.software.ibm.com/ebusiness/library.html
24)HowtoIcreatedynamicGIFsformyJSP?TOC
From:MattiKotsalainen<matti@RAZORFISH.COM>
IfyouwanttocreateGIFs,useACMElabsexcellentfreegifencoder(http://www.acme.com/),andthendosomethinglikethis:
Frameframe=null;
Graphicsg=null;
FileOutputStreamfileOut=null;
try{
//createanunshownframe
frame=newFrame();
frame.addNotify();
//getagraphicsregion,usingtheframe
Imageimage=frame.createImage(WIDTH,HEIGHT);
g=image.getGraphics();
//manipulatetheimage
g.drawString("Helloworld",0,0);
//getanouputstreamtoafile
fileOut=newFileOutputStream("test.gif");
GifEncoderencoder=newGifEncoder(image,fileOut);
encoder.encode();
}catch(Exceptione){
;
}finally{
//cleanup
if(g!=null)g.dispose();
if(frame!=null)frame.removeNotify();
if(fileOut!=null){
try{fileOut.close();}
catch(IOExceptionioe){;}
}
}
25)DoyouknowwhereIcouldgetsomecodethatwouldencodesomethingtotheHTMLDTDstandard?TOC
Asamatteroffact...
(NB:ThisisanimplementationoftheHTMLEncodefunctionthatASPhas)
From:EricLunt<elunt@YAHOO.COM>
Somewhereinmynet-travelsIpickedupthisversionwhichperformsprettywell:
/**
*ReturnsanHTMLrenditionofthegiven<code>String</code>.Thiswas
*writtenby<ahref=mailto:kimbo@biddersedge.com>KimboMundy</a>.
*@paramtextA<code>String</code>tobeusedinanHTMLpage.
*@returnA<code>String</code>thatquotesanyHTMLmarkup
*characters.Ifnoquotingisneeded,thiswillbe
*thesameas<code>text</code>.
*/
publicstaticStringasHTML(Stringtext){
if(text==null)
return"";
StringBufferresults=null;
char[]orig=null;
intbeg=0,len=text.length();
for(inti=0;i<len;++i){
charc=text.charAt(i);
switch(c){
case0:
case&:
case<:
case>:
case":
if(results==null){
orig=text.toCharArray();
results=newStringBuffer(len+10);
}
if(i>beg)
results.append(orig,beg,i-beg);
beg=i+1;
switch(c){
default://case0:
continue;
case&:
results.append("&");
break;
case<:
results.append("<");
break;
case>:
results.append(">");
break;
case":
results.append(""");
break;
}
break;
}
}
if(results==null)
returntext;
results.append(orig,beg,len-beg);
returnresults.toString();
}
26)Whatispagecompilation?TOC
See(30)
你希望java的IDE整合。这个是没有必要的,重要的是你理解java有多深以及怎么组织你的代码,即使没有IDE,代码照样能够编译运行的。 |
|