学习java日志

来源:互联网 发布:中国次贷危机 知乎 编辑:程序博客网 时间:2024/04/29 06:12

最近学习JSF,搞个配置弄了我半个月。平台:tomcat6.0+jdk1.5+MyEclipse6.0。之前把JSF第一步看了22章,到5.1才开始弄配置。废话不多说把问题列下:

1,messages国际化问题,由于messages文件都放在scr.com文件夹下,在使用是没有加上包名com.messages

2,MyEclipse6自带有tomcat与自己安装的tomcat产生冲突,使用时关掉一个就好了.

3,jdk6中%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib/tools.jar没有这两个包,jdk1.5中有.把jdk换成1.5的就好了.

4,由于每次输入路径时后缀为jsp,产生信息: Server startup in 15366 ms2008-5-14 14:30:14 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() for servlet jsp threw exceptionjava.lang.RuntimeException: Cannot find FacesContextat javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1797)...

错误.一开始index页面跳转其它页面时用jsp后缀没问题.但直接输入其它页面就有问题.

由于web.xml中后缀定为.faces所以用.faces就没有问题.

5,还有一个tomcat数据库连接问题tomcat目录下/conf/context.xml配置如下<Context>    <!-- Default set of monitored resources -->     <WatchedResource>WEB-INF/web.xml</WatchedResource>      <!-- Uncomment this to disable session persistence across Tomcat restarts -->     <!--    <Manager pathname="" />    -->    <!-- Uncomment this to enable Comet connection tacking (provides events         on session expiration as well as webapp lifecycle) -->    <!--    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />    --><Resource name="jdbc/jsfdb" auth="Container" type="javax.sql.DataSource"               maxActive="10" maxIdle="3" maxWait="10000"               username="root" password="admin" driverClassName="com.mysql.jdbc.Driver"               url="jdbc:mysql://localhost:3306/test"/></Context>

应用程序下的web.xml配置加上如下代码:

<resource-ref>    <res-ref-name>jdbc/jsfdb</res-ref-name>    <res-type>javax.sql.DataSource</res-type>    <res-auth>Container</res-auth>  </resource-ref>  数据库连接程序如下://获得数据源对象                    Context initCtx=new InitialContext();            if (initCtx==null) throw new DaoException("error_jndi_Context");                               DataSource ds=(DataSource)initCtx.lookup("java:comp/env/jdbc/jsfdb");            if (ds==null) throw new DaoException("error_jndi_find");                         //获得数据库连接           conn=ds.getConnection();            if (conn==null) throw new DaoException("error_database_conn");mysql的驱动程序放入tomcat/lib/目录下。

在tomcat6版本中,context元素已经从server.xml文件中独立出来了,放在一个context.xml文件中。因为server.xml是不可动态重加载的资源,服务器一旦启动了以后,要修改这个文件,就得重启服务器才能重新加载。而context.xml文件则不然,tomcat服务器会定时去扫描这个文件。一旦发现文件被修改(时间戳改变了),就会自动重新加载这个文件,而不需要重启服务器。我们当然推荐把应用需要的JNDI资源配置在context.xml文件中,而不是server.xml文件中。由于之前配置在server.xml文件中,所以出现问题(说是数据源找不到)。后面也不配置改在context.xml中,还是有问题,由于没有重启问题。现在明白了。

相关知识:

指定的应用可用顾名思义,一个指定的应用可用的context元素,意味着这是一个只有指定的引擎,指定的虚拟主机,指定的应用才可以使用的context元素。假定我们这个元素是为一个名叫 FiberScheduler的web应用创建的,那么这个web应用的放置路径应该是目录 ${tomcat6}/webapps/FiberScheduler(当然,如果你使用的是war包的话,那么就应该是 ${tomcat6}/webapps/FiberScheduler.war 文件了)。所以,我们的context元素应该指定属性 path=”FiberScheduler” docBase=”FiberScheduler”。然后,这是一个可以动态重新加载的资源,所以我们应该指定属性 reloadable=”true”。现在,我们的context元素的开始tag看起来是这个样子:<Context path="FiberScheduler"              docBase="FiberScheduler"           debug="5"             reloadable="true"             crossContext="true">