存档

文章标签 ‘java’

解决Tomcat7.0无法启动

2010年7月4日

因为工作要用到Java和Eclipse了,没办法,只有先自行练习一下了。

把 Tomcat 7.0和MyEclipse Download下来一试,具体安装步骤,网上一大遍,这里就不细讲,需要的朋友可留言或直接在网上Google一下。

写了一个Demo,调用,总是显示一个错误,很是奇怪。其错误如下所示:

java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory

at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:55)

Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory

at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

at java.lang.ClassLoader.loadClass(ClassLoader.java:307)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

… 1 more

Exception in thread “main”

奇了怪了,一切配置都是正常了, 所有JAVA_HOME、CLASSPATH之类的都正常,怎么会出现这个问题呢?

于是百度一下,结果发现别说“百度一下”,就是他妈的“百度一辈子”,也找不解决办法。算了,我还去Google一下吧。。。

终于在世界的某个角落被我发现了这种问题的解决办法,遇到相同问题的兄弟且听我慢慢道来。

具体的解决方案就是:

1. In Eclipse, Open the “Server” tab.
2. Double click on the “Tomcat6″ entry to see the configuration.
3. Then click on the “Open launch configuration” link in the “General information” block.
4. In the dialog, select the “Classpath” tab.
5. Click the “Add external jar” button.
6. Select the file “/usr/share/tomcat6/bin/tomcat-juli.jar”
7. Close the dialog.
8. Start tomcat 6 from Eclipse.

上图最直接,如下所示。

重新启动Tomcat 7.0,问题解决。不知道这个问题是myEclipse8.5的原因还是怎么回事,有了解的兄弟可以来一起交流交流。

国内顺利兄的解决方案:http://www.blogjava.net/lishunli/archive/2010/07/01/325019.html

国外某位老兄的方案:http://mianniu.com/programming-world/java-lang-noclassdeffounderror-orgapachejulilogginglogfactory-at-org-apache-catalina-startup-bootstrap

tomcat , , , ,

执行innerHTML中的Javascript代码

2009年4月10日

之前曾讲到采用set_innerHTML函数实现执行innerHTML中的JAVASCRIPT代码,其中讲到一种方法就是采用JS创建一个iframe的方式。

这里就将该方式的实现作一个介绍。

在我们使用AJAX的时候,经常要用到innetHTML来更新对象的内容,但是对于更新的<script>脚本程序浏览器却无法执行,我前面AJAX初学常遇问题解答这篇文章曾提到过这个问题,它不执行的原因是:<script>标签只在浏览器第一次文档加载中被解析,下面介绍怎么样让<script>跑起来。

分析问题
既然<script>只在文档加载中才被解析,那么我就得调用document.write()方法来重新加载一次,但是这样的话原来页面的内容也会被覆盖掉了,所以不得不用IFRAME把document.write()装载起来。

解决问题
var jsCode = 需要执行的JS代码
var jsIframe = document.createElement(“iframe”);
jsIframe.style.display = “none”;//把jsIframe隐藏起来
document.body.appendChild(jsIframe);
with(window.frames[window.frames.length - 1]){
document.open();
document.write(jsCode); //执行JS代码
document.close();
}
document.body.removeChild(jsIframe);//执行后删除iframe对象
这里需要注意一个问题,因为jsCode是在iframe中运行,所以所有的页面元素都在iframe父对象之下,要调用页面元素对象必须得用 parent.obj 这种方式。

另外一种方法:

用dom动态创建一个script对象
var script=document.createElement(“script”);
script.src=”XXXX.js”;
document.body.appendChild(script);

DIV/CSS, HTML, Javascript , , ,