John John
John John

Reputation: 43

Remove Spacing between JSP variables

have a problem with the spacing between this jsp calls

<tr>    
            <%=Constants.getTextInput("", Texts.RNG_IDENT_MSG, "", "", 19)%>

            <%=Constants.getTextInput("", Texts.RNG_IDENT_MSG_UNTIL, "", "", 19)%>

</tr>   

In the screen there's a space between them, that i want to remove. Can someone help me?

P.S. i tried css and other formats but still nothing.

P.S.2: This is in a HTML page and getTextInput it's a function to "create" a box

Upvotes: 0

Views: 1843

Answers (1)

code_angel
code_angel

Reputation: 1537

You can use the directive trimDirectiveWhitespaces

<%@ page trimDirectiveWhitespaces="true"%>

This should remove white spaces between actions, scriptlets and directives.

Here an example of what i get on Glassfish 4.0:

with <%@ page trimDirectiveWhitespaces="true"%> in the jsp

<%@ page trimDirectiveWhitespaces="true"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<table>


<tr>    
            <%="1111111111"%>

            <%="2222222222"%>


            <c:out value="c:out"></c:out>

            <c:out value="LOOP"></c:out>


            <c:forEach begin="1" end="5" step="1" var="y">

                ${'qqqqq'}    ${'RRR'}

                <c:out value="c:out"></c:out>   

                <% out.println("InTheLoop"); %>         

            </c:forEach>
</tr>  

</table>

</body>
</html>

Source code received in browser:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<table>


<tr>    
            11111111112222222222c:outLOOPqqqqqRRRc:outInTheLoop
qqqqqRRRc:outInTheLoop
qqqqqRRRc:outInTheLoop
qqqqqRRRc:outInTheLoop
qqqqqRRRc:outInTheLoop

</tr>  

</table>

</body>
</html>

The same JSP code as above but with <%@ page trimDirectiveWhitespaces="false"%>
Or without trimDirectiveWhitespaces at all
produce the folowing code received in browser:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<table>


<tr>    
            1111111111

            2222222222


            c:out

            LOOP




                qqqqq    RRR

                c:out   

                InTheLoop




                qqqqq    RRR

                c:out   

                InTheLoop




                qqqqq    RRR

                c:out   

                InTheLoop




                qqqqq    RRR

                c:out   

                InTheLoop




                qqqqq    RRR

                c:out   

                InTheLoop



</tr>  

</table>

</body>
</html>

So with trimDirectiveWhitespace="true":

  • you can remove whitespaces between actions, scriptlets, expressions, directives.
  • But you can NOT remove whitespaces between other html tags

Upvotes: 3

Related Questions