⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jspapp.xtp

📁 解压在c盘
💻 XTP
字号:
<title css='default.css'>JSP Applications</title><summarylist/><section title='Introduction'>JSP groups pages into applications which share common state.  Abulletin board application groups pages for article reading, grouplisting, user registration, and new article posting into a singleapplication.<p/>Applications can keep track of user sessions, giving the users theillusion of a single application out of disjointed pages.<ul><li/>JSP organizes applications with an .application <ahref='#dir'>directory</a>.<li/>The <a href='#global'>global.jsa</a> file contains commondeclarations and procedures for starting and stopping sessions andapplications.<li/><a href='#session'>Sessions</a> share state for a user's visit tothe site.</ul></section><section name='dir' title='.application directory'>The .application directory organizes an application.  It defines anapplication docroot by its presense.  All files and directories in thedocroot are part of the same application.<deftable title='.application contents'><tr><th>File/Directory</th><th>Contents</th></tr><tr><td>global.jsa</td><td>control file</td></tr><tr><td>scripts</td><td>common scripts</td></tr><tr><td>data</td><td>file data, e.g. text and xml</td></tr><tr><td>beans</td><td>Java class files for beans</td></tr><tr><td>tags</td><td>Java class files for tag compilation</td></tr></deftable><example title='Example directory structure'>newsgroup/              // application docroot  .application/         // application data    global.jsa          // global control    scripts/            // included scripts      common.es    data/               // application storage      art1.xml          // example article      art2.xml          // another article    beans/              // application beans      article.class     // Java article code    tags/               // application tags      dateHandler.class // date tag  list.jsp              // list articles  read.jsp              // read an article  post.jsp              // post an article</example><subsection title='Scripts'>JSP applications can group common functions and classes into scriptfiles, organizing and simplifying the application.  The individualpages can then <a href='statements.html#import'>import</a> the commonscripts to use them.  JSP pages can focus on HTML presentation and the scriptlibraries can concentrate on the content.<p/>As described in the <a href='statements.html#import'>import</a>documentation, <resin/> searches for imported scripts along aSCRIPTPATH.  For JSP pages, the SCRIPTPATH looks in the applicationscript directory first, then in the global libraries.<def title='JSP SCRIPTPATH'>  $APPDIR/.application/scripts    :$RESIN_HOME/scripts</def></subsection><subsection title='Data'>The data subdirectory of .application can contain any data the JSPapplication needs to store.  It could contain persistent state for acounter, to the entire article tree for a complicated discussionserver.<p/>The <a href='file.html'>File</a> object in a JSP script uses.application/data as its current directory.</subsection><subsection title='Tags'>JSP 1.0 provides an extensible tagarchitecture, allowing applications to design their own activetags.  The tag handlers are Java classes extending the<code/ChunkHandler/> interface.  When the JSP parser encounters a newtag, it looks in tags for a matching class.</subsection></section><section name=global title='global.jsa'>The global.jsa file contains common declarations, application andsession bean declarations, and event handlers.  Its structureresembles to a JSP file, except that it never creates content.<p/>Session and application beans must be declaredin a global.jsa <a href='jsp.html#usebean'>jsp:usebean</a> directive.Only page beans may be declared in a *.jsp file.  Theapplication beans will be instantiated when the first page of theapplication is accessed and will persist until the server shuts down.<p/><a href='jsp.html#error'>Error pages</a> global to the entireapplication may be declared in the global.jsa file.  Local error pagedeclarations override the global declarations.<p/>The <a href='jsp.html#language'>language</a> declared in theglobal.jsa file is local to the global file.  It only declares thelanguage for the <a href='jsp.html#decl'>declaration</a> section andthe event handlers.<subsection title='Event Handlers'>Applications can declare event handlers to execute when an applicationstarts or stops and when a session starts and stops.  The eventhandlers can initialize state, read data from storage, and store thefinal state when the server shuts down.<p/>Applications start on the first page access.  The application eventhandlers <a href='jsp.html#appOnStart'>jsp:application:onStart</a> and<a href='jsp.html#appOnEnd'>jsp:application:onEnd</a>can use the <a href='jsp.html#application'>application</a> object.<p/>Sessions start when a page accesses session state or when asession bean is created.  Sessions end when the server times them out,when the application ends, or when they are invalidated.  The sessionevent handlers <a href='jsp.html#sessionOnStart'>jsp:session:onStart</a> and<a href='jsp.html#sessionOnEnd'>jsp:session:onEnd</a>can use the <a href='jsp.html#session'>session</a> and<a href='jsp.html#application'>application</a> objects.<example title='Persistent Storage of Counter'>&lt;jsp:application:onStart&gt;  var file = File("counter");  if (file.exists()) {    var is = file.openRead();    var counter = new Number(is.readln());    is.close();  } else    var counter = 0;  application.attributes.counter = counter;&lt;/jsp:application:onStart&gt;&lt;jsp:application:onEnd&gt;  var os = File("counter").openWrite();  os.writeln(application.attributes.counter);  os.close();&lt;/jsp:application:onEnd&gt;</example></subsection></section><section name=session title='Sessions'>Session variables let applications keep track of the user as she movesthrough the site.  Any e-commerce site needs this capability to keeptrack of the user's purchases.<p/>JSP sessions start when the page accesses the <ahref='jsp.html#session'>session</a> variable.  If a page never usessessions, the jsp:session:onStart code will not execute and the webserver will not send the client any cookies.<p/>Sessions end when the session times out, when the session isinvalidated, or when the application ends.<p/><resin/> locks the session variable before executing the page.  SoJSP applications don't need to worry about synchronizing the sessionvariable.</section><section name=beans title='JSP Beans'><p/>Java Beans get first class treatment in JSP 1.0.  Beans can becreated for a page, across a session, or for the entire application.<p/>The .application/beans subdirectory can contain <ahref='jspapp.html#beans'>application beans</a> used by <ahref='jsp.html#usebean'>jsp:usebean</a>.  These are simply Javaclasses implementing the bitmechanic work of an application.<p/>For example, a shopping cart application may have a set of Javaclasses that perform the security necessary for credit cardprocessing.  The application can put those classes in the beansdirectory and access them from the JSP page.Beans can be created with different lifetimes.<ul><li/>Application beans last the lifetime of an application.<li/>Session beans last for a user's session.<li/>Page beans only last for a single page.</ul><subsection title='Accessing Beans'>Each bean is defined with a <a href='jsp.html#usebean'>jsp:usebean</a>directive.  Page beans are defined in the JSP page. Session andapplication beans are defined in the global.jsa file.<p/>JSP assigns the created bean object to the <resinscript/> variablenamed by jsp:usebean.<p/>In addition, the created beans are stored in JSP variables: pagebeans are stored in <code/request/>, session beans are stored in<code/session/>, and application beans are stored in<code/application/>.  Storing the beans in the JSP variables letsother beans and functions retrieve the beans.<example title='Beans in variables: test.jsp'>&lt;jsp:usebean name='test' class='java.util.Hashtable'&gt;&lt% test.put("a", 1); %&gt;&lt%= test.get("a"); %&gt;</example><example><example title='Page beans in request: test.jsp'>&lt;jsp:usebean name='test' class='java.util.Hashtable'&gt;&lt;%   var t = request.attributes["beans/test"]   t.put("a", 1);%&gt;&lt%= test.get("a"); %&gt;</example><results>1</results></example></subsection></section>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -