關於tomcat的使用小技巧(備註)

對tomcat使用不少,可是隻是很基礎的, 如今寫下一些功能的使用,供本身備註。 html

JNDI數據源 java

context.xml配置文件</Context>中
<Resource name="jndi/demo"   
                auth="Container"   
                type="javax.sql.DataSource"   
                driverClassName="oracle.jdbc.driver.OracleDriver"   
                url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL"   
                username="scott"   
                password="tiger"   
                maxActive="20"   
                maxIdle="10"   
                maxWait="10000"/>

web.xml web

<resource-ref>  
  <description>JNDI DataSource</description>  
  <res-ref-name>jndi/demo</res-ref-name>  
  <res-ref-type>javax.sql.DataSource</res-ref-type>  
  <res-auth>Container</res-auth>  
</resource-ref>

程序中 sql

Context ctx = new InitialContext();  
        DataSource ds = (DataSource) ctx.lookup("java:comp/env/jndi/demo");

     關於路徑的問題server.xml ,使用jfinal,就是默認路徑該使用什麼 tomcat

<Context docBase="jfinalDemp" path="" reloadable="true" source="org.eclipse.jst.jee.server:jfinalDemp"/></Host>

另外,若是要使用默認localhost進入,渲染時會用默認的文件名,可是不容許直接訪問系統文件,要經過jfinal,so,不要使用index.html等 oracle

 引用一段話 eclipse

這個問題的根本緣由是因爲 tomcat在接收到 http://localhost/ 請求後,會首先去查找 tomcat_home/conf/web.xml文件中的welcome-file-list所指定的文件,若是找到相應的文件則直接返回而不去理會應用中的Filter配置。要解決這個問題有兩個辦法:一是讓tomcat找不到這個文件,便可以把index.html改成main.html等等其它名稱。二是改掉或者去掉welcome-file-list配置。前者更加優雅。注意,這個問題不單單出如今根目錄「/」,其它目錄下的index.html也要注意,jetty不存在這個問題。

設置默認編碼:server.xml 編碼

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
相關文章
相關標籤/搜索