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

📄 bean.xtp

📁 解压在c盘
💻 XTP
字号:
<s1 title="Adding a Bean"><p>This example will use a Java bean to create a simple hit counter.There's nothing complicated about Java beans.  Java beans are justJava classes that follow some simple naming conventions.  Resin makescreating beans simple.  Resin will automatically compile Java sourcein the <var>WEB-INF/classes</var> directory.</p><p>With the configuration you're using now, <var>WEB-INF/classes</var>is in:</p><def><jsp:expression>application.getRealPath("/WEB-INF/classes")</jsp:expression></def><p>JSP encourages beans with the jsp:useBean tag.  JSP willautomatically create a new bean and store it in the applicationobject.</p><p>The example creates a Counter bean and stores it in theapplication object.  Each request calls <code>getHit()</code> to getthe next value of the counter.</p><example title='counter.jsp'>&lt;%@ page language='java' %&gt;&lt;jsp:useBean id='counter'             scope='application'             class='test.Counter'/>Visitor &lt;jsp:getProperty name='counter'                         property='hit'/></example><p>The source of the bean looks like:</p><example title='test/Counter.java'>package test;public class Counter {  private int hits;  public synchronized int getHit()  {    return ++hits;  }}</example><p>Now, create the bean in the bean directory and load counter.jsp:<def><jsp:expression>application.getRealPath("/WEB-INF/classes/test/Counter.java")</jsp:expression></def></p><p>You should then make some changes to Counter.java and reload to see theauto-recompilation.  Also, introduce some errors to get familiar withthe error reporting.</p><p>You can also compile the bean separately and then put Counter.class in<def><jsp:expression>application.getRealPath("/WEB-INF/classes/test/Counter.class")</jsp:expression></def></p><s2 title='JSP translation'><p>The special <var/jsp:useBean/> tag translates into standard JSP.Here's the translation:</p><example>&lt;%@ page language='java' %&gt;&lt;%test.Counter counter;synchronized (application) {  counter = (test.Counter) application.getAttribute("counter");  if (counter == null) {    counter = new test.Counter();    application.setAttribute("counter", counter);  }}%>Visitor &lt;%= counter.getHit() %></example></s2><s2 title='Autocompile Configuration'><p>In a real development environment, your Java source directory maybe different from the web server directory.  The resin.conf lets youselect any directory as the Java source and Java classes.</p><example>&lt;caucho.com>&lt;http-server>  &lt;classpath id='WEB-INF/classes'             source='/home/ferg/ws/src'/>&lt;/http-server>&lt;/caucho.com></example></s2></s1>

⌨️ 快捷键说明

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