有時候我們在編輯配置文件, 寫標籤時候, 按提示鍵沒有提示, 很不方便, 這時候我們只要有相應的 dtd 文件, 我們就可以關聯起來, 讓提示鍵可以用了.
拿 Struts 的配置文件 struts.xml 來說吧.
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="default" namespace="/" extends="struts-default"> <action name="emp-*" class="employeeAction" method="{1}"> <result name="list">/WEB-INF/views/emp-list.jsp</result> </action> </package> </struts>
在 DOCTYPE 中有一個 http://struts.apache.org/dtds/struts-2.3.dtd 賦值這個東西, 然後打開 Eclipse 中的 windows -> preferences -> XML -> XML Catalog, 在右側 選擇 Add
記住: Key type 一定要選擇 URL, 否則不會生效的. 如果複製:
-//Apache Software Foundation//DTD Struts Configuration 2.3//EN
這個的話, Key type 就選擇 Public ID.
然後點 Ok, 完成配置! 把 struts.xml 文件關閉重新打開, 就有提示了.
大功告成!!!