1. 程式人生 > >解決Unable to find taglib [cr] for URI: [WBE-INF/tlds/testlib.tld]] with root cause的可能性方案

解決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設計思想一樣,在遇到問題的時候,去提供的例程裡尋找答案也是不錯的選擇

共勉!