Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove line breaks after JSP tags? [duplicate]

How to remove line breaks after JSP tags?

For example, if in JSP page has code with tag like this

<%@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>

Than in output result will be one line break at line one.

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

How I can remove unneeded line break at the first line?

JSP processed with Spring Web MVC.

Thanks.

like image 779
Arthur Avatar asked Oct 31 '22 23:10

Arthur


1 Answers

Copied from Strip whitespace from jsp output There is a trimWhiteSpaces directive that should accomplish this,

In your JSP:

<%@ page trimDirectiveWhitespaces="true" %>

Or in the jsp-config section your web.xml (Note that this works starting from servlet specification 2.5.):

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

Unfortunately if you have a required space it might also need strip that, so you may need a non-breaking space in some locations.

like image 162
Arthur Avatar answered Nov 08 '22 10:11

Arthur