JSP trimSpaces指令不起作用! [英] JSP trimSpaces directive not working!

查看:143
本文介绍了JSP trimSpaces指令不起作用!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用web.xml中的trimSpaces指令来修剪JSP空格,但是它不起作用.这是我的web.xml:

I'm trying to trim JSP whitespace using the trimSpaces directive in my web.xml, but it's not working. Here's my 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>

我是新来的,不确定如何调试问题.我尝试将< init-param>在< servlet>内部标签,但是没有用. xml模式可能有问题吗?还是我的JSP版本不正确? (我几个月前才安装Tomcat,所以是最近的)

I'm new at this and not sure how to go about debugging the problem. I tried putting the <init-param> inside the <servlet> tags, but that didn't work. Maybe there's something wrong with the xml schema? Or maybe my JSP version isn't correct? (I only installed Tomcat a few months ago, so it's pretty recent)

我正在使用Tomcat7.如您所见,还在使用Spring.

I'm using Tomcat 7. Also using Spring, as you can see.

有什么建议吗?

推荐答案

JspServlet<init-param>需要放入 servletcontainer 本身的web.xml中,而不是您的Webapp中.转到Tomcat安装文件夹,然后打开/conf/web.xml文件.找到JspServlet<servlet>条目,然后在其中添加<init-param>.

The <init-param> for the JspServlet needs to go in the web.xml of the servletcontainer itself, not of your webapp. Go to the Tomcat installation folder and open the /conf/web.xml file. Locate the <servlet> entry of the JspServlet and add the <init-param> there.

例如,如果您想在Webapp的web.xml中进行全局配置,例如,因为servletcontainer配置不在您的控制范围内,则需要设置<jsp-config><trim-directive-whitespaces>属性.

If you'd like to configure it globally in the web.xml of your webapp, for example because the servletcontainer configuration is outside your control, then you need to set the <trim-directive-whitespaces> property of the <jsp-config> instead.

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <trim-directive-whitespaces>true</trim-directive-whitespaces>
     </jsp-property-group>
</jsp-config>

这篇关于JSP trimSpaces指令不起作用!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆