[收藏]Tomcat使用技巧

          Posted on 2006-03-15 02:19 ikingqu 閱讀(197) 評論(0)  編輯  收藏 所屬分類: Web/App Server

          TOMCAT使用技巧


          1 增加一個虛擬目錄
          在server.xml文件中增加
          <Context path="/oicq" docBase="myweb" debug="0" reloadable="true">
              </Context>
          myweb說明其相對webapps的位置,是物理存在的目錄;
          /oicq說明其相對web URL的路徑,是一個虛擬的路徑,如:http://localhost/oicq

          2 配置服務器的端口
          在標準server.xml文件的第56行,修改port = “8080” 為你所希望使用的端口號,如:80

          3 web.xml文件的設置

          默認(歡迎)文件的設置
          在h:\tomcat4\conf\web.xml中,<welcome-file-list>與IIS中的默認文件意思相同。
          <welcome-file-list>
          <welcome-file>index.html</welcome-file>
          <welcome-file>index.htm</welcome-file>
          <welcome-file>index.jsp</welcome-file>
          </welcome-file-list>

          報錯文件的設置
          <error-page>
          <error-code>404</error-code>
          <location>/notFileFound.jsp</location>
          </error-page>
          <error-page>
          <exception-type>java.lang.NullPointerException</exception-type>
          <location>/null.jsp</location>
          </error-page>
          如果某文件資源沒有找到,服務器要報404錯誤,按上述配置則會調用

          H:\tomcat\webapps\ROOT\notFileFound.jsp。
          如果執行的某個JSP文件產生NullPointException ,則會調用H:\tomcat4\webapps\ROOT\null.jsp

          典型的JSP錯誤頁面應該這樣寫:
          <%@ page isErrorPage=”true”%>
          出錯了:<p> 錯誤信息: <%= exception.getMessage() %></p>

          Stack Trace is :
          <pre>
          <font color="red">
          <%
          java.io.CharArrayWriter cw = new java.io.CharArrayWriter();
          java.io.PrintWriter pw = new java.io.PrintWriter(cw,true);
          http://www.ChinaJavaWorld.com/ exception.printStackTrace(pw);
          out.println(cw.toString());
          %>
          </font>
          </pre>

          會話超時的設置
          設置session 的過期時間,單位是分鐘;
          <session-config>
          <session-timeout>30</session-timeout>
          </session-config>

          過濾器的設置
          <filter>
          <filter-name>FilterSource</filter-name>
          <filter-class>project4. FilterSource </filter-class>
          </filter>
          <filter-mapping>
          <filter-name>FilterSource</filter-name>
          <url-pattern>/WwwServlet</url-pattern>
          (<url-pattern>/haha/*</url-pattern>)
          </filter-mapping>

          過濾:
          1) 身份驗證的過濾Authentication Filters
          2) 日志和審核的過濾Logging and Auditing Filters
          3) 圖片轉化的過濾Image conversion Filters
          4) 數據壓縮的過濾Data compression Filters
          5) 加密過濾Encryption Filters
          6) Tokenizing Filters
          7) 資源訪問事件觸發的過濾Filters that trigger resource access events XSL/T 過濾XSL/T filters
          9) 內容類型的過濾Mime-type chain Filter 注意監聽器的順序,如:先安全過濾,然后資源,然后內容類型等,這個順序可以自己定。
           

          posts - 4, comments - 5, trackbacks - 0, articles - 60

          Copyright © ikingqu

          主站蜘蛛池模板: 高唐县| 仪陇县| 读书| 新安县| 五寨县| 清水县| 揭东县| 锦州市| 光山县| 山阳县| 蓬莱市| 德昌县| 会泽县| 通渭县| 阿合奇县| 靖州| 师宗县| 新密市| 阜宁县| 玉龙| 都匀市| 祁门县| 台南市| 仁化县| 江西省| 天水市| 大英县| 左权县| 苗栗市| 五常市| 札达县| 额济纳旗| 上饶市| 渭源县| 万全县| 延津县| 昌邑市| 天门市| 泾源县| 镇雄县| 康乐县|