对tomcat使用很多,但是只是很基础的, 现在写下一些功能的使用,供自己备注。
JNDI数据源
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
<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>
程序中
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jndi/demo");
关于路径的问题server.xml ,使用jfinal,就是默认路径该使用什么
<Context docBase="jfinalDemp" path="" reloadable="true" source="org.eclipse.jst.jee.server:jfinalDemp"/></Host>
另外,如果要使用默认localhost进入,渲染时会用默认的文件名,但是不允许直接访问系统文件,要通过jfinal,so,不要使用index.html等
引用一段话
这个问题的根本原因是由于 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"/>