【问题标题】:How to remove line breaks after JSP tags? [duplicate]如何去除 JSP 标签后的换行符? [复制]
【发布时间】:2014-05-24 09:11:38
【问题描述】:

如何去除JSP标签后的换行符?

例如,如果在 JSP 页面中有这样的标记代码

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${pageTitle}</title>
    </head>

输出结果将在第一行换行。

!HERE_LINE_BREAK!
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>

如何删除第一行不需要的换行符?

使用 Spring Web MVC 处理的 JSP。

谢谢。

【问题讨论】:

    标签: java jsp spring-mvc


    【解决方案1】:

    复制自Strip whitespace from jsp output 有一个 trimWhiteSpaces 指令可以完成这个,

    在您的 JSP 中:

    <%@ page trimDirectiveWhitespaces="true" %>
    

    或者在 jsp-config 部分中您的 web.xml(请注意,这从 servlet 规范 2.5 开始。):

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

    不幸的是,如果您有所需的空间,它可能还需要剥离它,因此您可能在某些位置需要一个不间断的空间。

    【讨论】:

      猜你喜欢
      • 2014-12-22
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 1970-01-01
      • 2013-01-05
      • 2019-06-02
      • 2010-09-18
      • 2017-09-21
      相关资源
      最近更新 更多