I have declared some taglibs and variables
in my jsp
page as below:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="site" scope="session" value="${site}"/>
<c:set var="thumb" scope="session" value="${thumbnail}"/>
<c:set var="geoCode" scope="session" value="${geoCode}"/>
...
<fmt:setLocale value="${local}" />
<fmt:setBundle basename="MessagesBundle" />
<!DOCTYPE html>
<head>
<meta charset="utf-8">
...
when I run the app and then view the source I see blank new lines on top of the source page:
.
<!DOCTYPE html>
<head>
<meta charset="utf-8">
I just placed a dot
to demonstrate the empty lines.
Any idea on how I can remove these empty lines?
A tag library defines a collection of custom actions. The tags can be used directly by developers in manually coding a JSP page, or automatically by Java development tools. A tag library must be portable between different JSP container implementations.
JSTL stands for JSP Standard Tag Library. JSTL is the standard tag library that provides tags to control the JSP page behavior. JSTL tags can be used for iteration and control statements, internationalization, SQL etc.
The taglib directive declares that your JSP page uses a set of custom tags, identifies the location of the library, and provides means for identifying the custom tags in your JSP page. The taglib directive follows the syntax given below − <%@ taglib uri = "uri" prefix = "prefixOfTag" >
The Jakarta Standard Tag Library (JSTL; formerly JavaServer Pages Standard Tag Library) is a component of the Java EE Web application development platform.
You need to tell the JSP servlet to trim directive whitespaces. You can achieve that by adding the following entry to webapp's web.xml
:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
Or, if you'd like to configure it server-wide instead of on a per-webapp basis, then consult the servletcontainer documentation on the matter. You didn't tell which one you're using, but in case of Tomcat, it'd be a matter of editing its /conf/web.xml
to add the following entry to the <servlet>
declaration of the JSP servlet:
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>
Unrelated to the concrete problem, your @page
contains a lot of default and repeated mess. It can be simplified as follows:
<%@page pageEncoding="UTF-8"%>
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