zl程序教程

您现在的位置是:首页 >  其他

当前栏目

web.xml引用外部xml文件。以及org.xml.sax.SAXException

文件WebXML 以及 引用 org 外部 SAX
2023-09-14 09:04:39 时间
很多时候因为各种各样的原因,需要在各种xml文件来引用外部的xml文件。 我遇到了两种,一种是普通配置的xml文件引用外部xml文件。 import resource= classpath:tuloginContext.xml / 这是相对路径,当然,这句代码的位置需要注意。这个在beans下面,与bean平级,如果写错了,会不执行,就会导入出错,或者就是

很多时候因为各种各样的原因,需要在各种xml文件来引用外部的xml文件。

我遇到了两种,一种是普通配置的xml文件引用外部xml文件。

可以用

import resource="classpath:tuloginContext.xml" /

这是相对路径,当然,这句代码的位置需要注意。这个在beans下面,与bean平级,如果写错了,会不执行,就会导入出错,或者就是不执行也不报错。

beans

import resource="classpath:tuloginContext.xml" /

bean /bean

/beans

另一种是web.xml引用外部xml文件。这个是我看大神写的。原网站如下。

http://www.blogjava.net/jiangjf/archive/2009/04/09/264685.html

我的需求和理解:

因为项目中很多东西需要放到web.xml中部署,或者,有一些相同的代码需要放到不同的web.xml中部署,所以,就用到了web.xml拆分。

根据文章介绍。

需要在文章顶部加上这个:

 !DOCTYPE web-app

 [ !ENTITY test SYSTEM "file:///D:/eclipse/workspace/Test/WebRoot/WEB-INF/test.xml" 

 !ENTITY admin SYSTEM "admin.xml" ] 
这里的test 和 admin 是自定义的名称。后面两个,分别是相对路径和绝对路径。
记住,是顶部,下面是我写的。

 ?xml version="1.0" encoding="UTF-8"? 

 !DOCTYPE web-app [ !ENTITY tulogin SYSTEM "tulogin.xml" ] 

 web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

 id="WebApp_admin" version="3.0" 
不能在 web-app 里面,否则会出错的。

错误代码如下:

七月 14, 2015 10:41:53 上午 org.apache.catalina.startup.ContextConfig parseWebXml

严重: Parse error in application web.xml file at jndi:/localhost/file-server/WEB-INF/web.xml

org.xml.sax.SAXException: Scanner State 24 not Recognized 

 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)

 at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)

 at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1537)

 at org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1883)

 at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1252)

 at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)

 at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)

 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)

 at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)

 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)

 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)

 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)

 at java.util.concurrent.FutureTask.run(Unknown Source)

 at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

 at java.lang.Thread.run(Unknown Source)
其实,就是位置不对,应该放到页面顶部。

在引用这段代码的位置,写这个就可以了

 tulogin; + 你自己定义的名称 + ;
还有一个问题。

项目部署的时候,会自动执行web.xml。所以,如果一个项目中,引用了另外项目的xml,这个,我不知道怎么解决这个问题。




mybatis xml文件热加载实现 本文博主给大家带来一篇 mybatis xml 文件热加载的实现教程,自博主从事开发工作使用 Mybatis 以来,如果需要修改 xml 文件的内容,通常都需要重启项目,因为不重启的话,修改是不生效的,Mybatis 仅仅会在项目初始化的时候将 xml 文件加载进内存。
Eclipse MyBatis1.4.2 generatorConfig 默认不生成XML文件,加了type= XMLMAPPER 也不起作用,解决方法 今天下载了最新的mybatis插件,生成不了XML文件,然后是一堆java注解文件,还有一堆报错。心头各种不爽,网上搜了很久,都是很旧的帖子,根据解决不了问题。最后自己在官网找到了答案,以后大家在搜索找不到答案,还是自己到官网翻文档吧! MyBatis 的官网generatorConfig说明如下: http://mybatis.org/generator/configreference/xmlconfig.html
【IntelliJ IDEA】idea中的插件之一:Free Mybatis plugin跳转插件的使用(方便在Dao接口和Mappper XML文件之间进行切换) 之前使用MyBatis框架或者是在IDEA中,发现Mapper接口和XML文件之间跳转十分的麻烦,我之前经常的操作是在Mapper接口中将接口名称复制一下,然后去查找对应的XML文件,打开后CRTL+F查找对应的xml实现,整个过程效率很低下,搜了搜果然有前辈已经出了一款IDEA的插件解决了这个问题,把这个好用的跳转插件推荐给大家。
Idea中指定xml文件失效 最近狮子在搞一个项目,需要用到数据库多表查询,所以在idea创建了一个xml文件,创建完成之后,这个文件居然只被识别位text文件,而且文件内容没有高亮,如图所示: