由于这个工作很简单,很快就完成了,输入地址直接看了下,是xml那种形式的,然后,产生树形结构的代码中的ajax部分调用这个xml,结果居然抛错,取不到responseXML中的元素。
我怎么想都不明白,明明看着是个xml,怎么就取不到。后来查FreeMarker配置的时候,在web.xml看到
<init-param>
<param-name>ContentType</param-name>
<param-value>text/html</param-value>
</init-param>
估计问题就在这里,于是想在页面加句什么把ContentType改成text/xml,但是没找到该怎么加,郁闷,只好在web.xml加了这么一段
<param-name>ContentType</param-name>
<param-value>text/html</param-value>
</init-param>
<servlet>
<servlet-name>freemarker_xml</servlet-name>
<servlet-class>
freemarker.ext.servlet.FreemarkerServlet
</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/WEB-INF/templates/xml/</param-value>
</init-param>
<init-param>
<param-name>NoCache</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>ContentType</param-name>
<param-value>text/xml</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>freemarker_xml</servlet-name>
<url-pattern>*.xml.ftl</url-pattern>
</servlet-mapping>
所有的xml模板都以.xml.ftl结尾,一测试,好了,说明原来看到的那个形似xml的东西它不是一个xml!!
<servlet-name>freemarker_xml</servlet-name>
<servlet-class>
freemarker.ext.servlet.FreemarkerServlet
</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/WEB-INF/templates/xml/</param-value>
</init-param>
<init-param>
<param-name>NoCache</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>ContentType</param-name>
<param-value>text/xml</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>freemarker_xml</servlet-name>
<url-pattern>*.xml.ftl</url-pattern>
</servlet-mapping>