我正在尝试使用我的 web.xml 中的 trimSpaces 指令来修剪 JSP 空白,但它不起作用。这是我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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_4.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
id="WebApp_ID"
version="2.4">
<display-name>MyWebApp</display-name>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>
</web-app>
我是新手,不确定如何调试问题。我尝试将
我正在使用 Tomcat 7。如您所见,还使用了 Spring。
有什么建议吗?
最佳答案
<init-param>
对于 JspServlet
需要进入 web.xml
servletcontainer 本身,而不是您的 webapp。转到 Tomcat 安装文件夹并打开 /conf/web.xml
文件。找到 <servlet>
输入 JspServlet
并添加 <init-param>
那里。
如果您想在 web.xml
中全局配置它你的 webapp,例如因为 servletcontainer 配置不在你的控制范围内,那么你需要设置 <trim-directive-whitespaces>
<jsp-config>
的属性(property)反而。
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
关于xml - JSP trimSpaces 指令不起作用!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5519642/