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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With