Community
Participate
Working Groups
I want to format my JSP page. I am using the JSP Editor. My Eclipse Settings are the following: General > Editors > Text Editors: Displayed tab width: 4 Insert spaces for tabs is selected Java > Code Style > Formatter : Click Edit > Indentation > General settings: Tab policy: Spaces Only Indentation size: 4 Tab size: 4 JavaScript > Code Style > Formatter : Click Edit > Indentation > General settings: Tab policy: Spaces Only Indentation size: 4 Tab size: 4 Web > CSS Files > Editor: Indent using spaces is selected Indentation size: 4 Web > HTML Files > Editor: Indent using spaces is selected Indentation size: 4 Web > JSP Files > Editor: Format JSP XML documents as HTML is selected XML > XML Files > Editor: Indent using spaces is selected Indentation size: 4 How to reproduce this bug: 1. Open a new JSP file 2. Replace the contents of the JSP with the following HTML: <%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%> <% StringBuilder test = new StringBuilder("This line does not have tabs on it!\n"); test.append("This line will have tabs on it.\n"); test.append("This line will too!\n"); %> <!DOCTYPE html> <html> <head> <title>Insert title here</title> <script type="text/javascript"> function () { alert(''); } </script> </head> <body> <%=test%> </body> </html> (Take note of the message appended in the StringBuilder test object) 3. CTRL + SHIFT + F (Format the page, below is a result of the format) <%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%> <% StringBuilder test = new StringBuilder("This line does not have tabs on it!\n"); test.append("This line will have tabs on it.\n"); test.append("This line will too!\n"); %> <!DOCTYPE html> <html> <head> <title>Insert title here</title> <script type="text/javascript"> function () { alert(''); } </script> </head> <body> <%=test%> </body> </html> 3.5 You can notice that there is unwanted space in the lines with test.append, that unwanted space happens to be tab characters. After some more investigation, I found the issue might be with the <script> tags in the html, so when I commented out the <script> tags, you can see the following happened: 1. Open a new JSP file 2. Replace the contents of the JSP with the following HTML: <%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%> <% StringBuilder test = new StringBuilder("This line does not have tabs on it!\n"); test.append("This line will NOT have tabs on it.\n"); test.append("This line will NOT have tabs on it too!\n"); %> <!DOCTYPE html> <html> <head> <title>Insert title here</title> <!-- <script type="text/javascript"> function () { alert(''); } </script> --> </head> <body> <%=test%> </body> </html> (Take note of the message appended in the StringBuilder test object) 3. CTRL + SHIFT + F (Format the page, below is a result of the format) <%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%> <% StringBuilder test = new StringBuilder("This line does not have tabs on it!\n"); test.append("This line will NOT have tabs on it.\n"); test.append("This line will NOT have tabs on it too!\n"); %> <!DOCTYPE html> <html> <head> <title>Insert title here</title> <!-- <script type="text/javascript"> function () { alert(''); } </script> --> </head> <body> <%=test%> </body> </html> You can see that there are no tabs anymore, but unfortunately, I am not in a position where I can remove <script> tags and/or JSP Scriptlet tags. If there is a setting that fixes this issue, then let me know, otherwise I believe this is a bug.