Java 如何为jsp格式配置eclipse?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18592682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How configure eclipse for jsp formatting?
提问by
I want to configure eclipse so that:
我想配置 eclipse 以便:
My Original Code Format:
我的原始代码格式:
name: <input type="text" value="${event.name}" name="name" /> <br /> description: <input type="text" value="${event.description}" name="description" /> <br />eventDate:<input type="date" value="${event.eventDate}" name="resumeUrl" /><br />
My Target Code Format:
我的目标代码格式:
name: <input type="text" value="${event.name}" name="name" />
<br />
description:
<input type="text" value="${event.description}" name="description" />
<br />
eventDate:
<input type="date" value="${event.eventDate}" name="resumeUrl" />
<br />
I want to get 1 line = 1 tag
!
我要得到1 line = 1 tag
!
How to configure eclipse to reformat my original to target format?
如何配置 eclipse 以将我的原始格式重新格式化为目标格式?
采纳答案by fujy
In eclipse:
在日食中:
- for Windows Open Window Menu -> choose Preferences
- for Mac Open EclipceMenu -> choose Preferences
- 对于 Windows 打开窗口菜单 -> 选择首选项
- 对于 Mac 打开 EclipceMenu -> 选择首选项
From the Preferences Window choose Web => HTML Files => Editor
从首选项窗口中选择 Web => HTML Files => Editor
From the Inline Elements:
view, add all tags that you want appear in one line
从Inline Elements:
视图中,添加您希望显示在一行中的所有标签
Now whenever you press CTRL+SHIFT+F, the JSP will be formatted to your new style
现在,每当您按CTRL+ SHIFT+ 时F,JSP 将被格式化为您的新样式
回答by Bhushan Kawadkar
you can use CTL+SHIFT+F
in eclipse but make sure you have opened jsp in jsp editor.
您可以CTL+SHIFT+F
在 eclipse中使用,但请确保您已在 jsp 编辑器中打开了 jsp。
if not then go to Eclipse - window - preferences - general - editors - File Associations
如果没有,则转到 Eclipse - 窗口 - 首选项 - 常规 - 编辑器 - 文件关联
and select file type as *.jsp and set JSP Editor as default
并选择文件类型为 *.jsp 并将 JSP 编辑器设置为默认值
回答by sunny
From eclipse Window Menu, choose Preferences
从 eclipse Window Menu 中,选择 Preferences
From the Preferences Window choose Web => HTML Files => Editor
从首选项窗口中选择 Web => HTML Files => Editor
Increase the
line widths and format the jsp page using ctrl+shift+F
.
增加线宽并使用 .jsp 格式化 jsp 页面ctrl+shift+F
。
回答by user3856049
No you can't simply format jsp(html & jsp scriplets) pages using ctrl+shift+f, if you use that keys it will make your code change the syntax, for example:
不,您不能简单地使用 ctrl+shift+f 格式化 jsp(html & jsp scriplets) 页面,如果您使用该键,它将使您的代码更改语法,例如:
{
String error = request.getAttribute("error") != null ? (String) request.getAttribute("error"): "";%>
}
this code will change it to
此代码将其更改为
{
String error = request.getAttribute("error") != null ? (String) request.getAttribute("error") : "";%>
},
after using the keys again you have to manually align this scriplets
再次使用按键后,您必须手动对齐此脚本
回答by Voka Wang
Maybe you can try this: Window -> Preference -> Web -> HTML Files ->Editor -> Formatting : change the "Line width" to 200 or larger
也许你可以试试这个:Window -> Preference -> Web -> HTML Files ->Editor -> Formatting :将“线宽”更改为 200 或更大