解决Unable to find taglib [cr] for URI: [WBE-INF/tlds/testlib.tld]] with root cause的可能性方案

最近在学习自定义JSP标签,按照网上的例程敲了一下发现出现500错误,错误信息Unable to find taglib [cr] for URI: [WBE-INF/tlds/testlib.tld]] with root cause

反复检查了Tomcat/logs中的信息和自己的配置路径确认没有问题之后,偶然想到可能是版本不同(网上的例程版本已经比较老了),然后打开Tomcat提供的example文件之后发现果然书写格式有许多不一样,接下来直接贴出对比:

存在问题的tld文件定义方法:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!DOCTYPE taglib
        PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
        "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
	<tlibversion>1.0</tlibversion>
	<jspversion>1.2</jspversion>
	<shortname>challen</shortname>
	
	<tag>
		<name>cr</name>
		<tagclass>com.challen.jsp.CopyRightTag</tagclass>
		<bodycontent>empty</bodycontent>
		<attribute/>
	</tag>
</taglib>
修改后可行的代码:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!DOCTYPE taglib
        PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
        "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
	<tlib-version>1.0</tlib-version>
	<jsp-version>1.2</jsp-version>
	<short-name>challen</short-name>
	
	<tag>
		<name>cr</name>
		<tag-class>com.challen.jsp.CopyRightTag</tag-class>
		<body-content>empty</body-content>
		<attribute/>
	</tag>
</taglib>


正如经常看到的那句话,MVC架构目前还没有一个成熟的理论或是模式给人们去学习,大家只能通过现有的例程去感受MVC设计思想一样,在遇到问题的时候,去提供的例程里寻找答案也是不错的选择

共勉!






猜你喜欢

转载自blog.csdn.net/u013576018/article/details/77040951