Jsps auto alignment of spaces

There is a good way to trim spaces created by JSP without resorting to the following methods:

  • trimSpaces jasper: directive can ruin your layout by placing significant spaces where you want.
  • surrounding areas that you want to crop using JSP comments by commenting on spaces. it makes JSP harder to edit and looks awful

I'd love to know if anyone knows a better way to selectively crop spaces in JSP

edit : now I am doing all my tags on one, for example:

<c:forEach var="date" items="${model.list}"><%-- --%><c:set var="dateStr"><ct:dateFormat date="${date.startDate}"/></c:set><%-- --%><option value="${dateStr}">${dateStr}</option><%-- --%></c:forEach> 
+4
source share
4 answers

Here you are dealing with the choice of the smallest of all. I would go with the jasper trimSpaces directive, and if you have spaces that are significant in your layout, you can strategically insert uppercase letters like this:

 <c:out value=" " /> 

or like this:

 ${ } 

Other options for trimming spaces that were not mentioned in your post:

  • Write a servlet filter that justifies spaces as a step in rendering a message (this should be smart enough not to trim โ€œsignificantโ€ spaces).
  • Put all your jsp tags on one line (just joke, don't do this!)
+2
source

there are places where you want them

Can you give an example? I really cannot imagine such a need.

Do you mean inside textareas? Inside HTML <pre> elements? Inside CSS white-space:pre stylized elements? In setting up Tomcat trimSpaces should consider them.

Or do you mean spaces for the layout? Well, they really don't belong. Consider replacing the CSS margin / padding properties and save the trimSpaces parameter.

+2
source
0
source

Try it: http://coldjava.hypermart.net/servlets/trimflt.htm I just implemented it myself as a servlet filter, it works.

Another option: htmlcompressor (google it, I can provide only 1 atm link ...)

taglib htmlcopressor allows you to use the shell, also has compressors for css and js.

0
source

All Articles