配置 Eclipse 以使用 Javascript 编辑器

发布于 2024-10-04 06:41:25 字数 375 浏览 0 评论 0原文

在 Eclipse 中编辑 JSP 时,

由于超出了本问题范围的原因,我创建了一个自定义 JavaScript 标记,我们将其称为 。这种类型的主体是纯 JavaScript,就像在常规

但是,当我的自定义标记中有 Javascript 代码时,它会被视为简单文本(没有颜色编码、没有正确的缩进等)。

我的问题是,如何使 Eclipse 在自定义 JSP 标记中使用特定编辑器?

When editing JSPs in Eclipse, the contents of <script> tags - i.e. Javascript code - is properly color coded and formated.

For reasons that go beyond the scope of this question, I have created a custom javascript tag, let's call it <sj:script>. The body of this type is pure javascript as you would have in a regular <script> tag.

However, when I have Javascript code within my custom tag, it is treated as simple text (no color coding, no proper indentation, etc).

My question is, how do I make Eclipse use a specific editor within custom JSP tags?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

碍人泪离人颜 2024-10-11 06:41:25

您可以尝试 MyEclipseAptana Studio。他们为网络开发提供了更好的编辑器。

但更好的方法是将 JS 放入不同的文件中,并使用

  1. 您可以使用更好的编辑器
  2. 浏览器可以缓存 JavaScript (而不是每次都将其与页面的其余部分一起下载)
  3. 您可以为 JavaScript 编写测试(当 JS 被劫持在 JSP 文件中时几乎不可能)。

[编辑] Eclipse 是开源的。下载 WTP 项目的代码,查找文本编辑器部分并搜索“脚本”。在您找到的所有位置中,也添加“sj:script”。

You can try MyEclipse or Aptana Studio. They offer much better editors for web development.

But a much better approach is to put the JS into a different file and reference that with <script src="...">:

  1. You can use a better editor
  2. The browser can cache the JavaScript (instead of downloading it every time with the rest of the page)
  3. You can write tests for the JavaScript (next to impossible when the JS is held hostage in a JSP file).

[EDIT] Eclipse is open source. Download the code for the WTP project, look for the text editor parts and search for "script". In all places that you find, add "sj:script", too.

苏别ゝ 2024-10-11 06:41:25

您是否在使用自定义标记的 jsp 中包含了标记库描述符文件?

Have you included the Tag Library Descriptor file in the jsp where you are using the custom tag?

倒带 2024-10-11 06:41:25

我有一个 Eclipse 插件列表,可以让 Eclipse 编辑 JS 文件:

http://www.delicious .com/powtac/javascript+eclipse

只需浏览链接并查看如何安装它们的不同描述。

I have a list of plugins for eclipse which enable eclipse to edit JS files:

http://www.delicious.com/powtac/javascript+eclipse

Just go trough the links and see the different descriptions how to install them.

鸠魁 2024-10-11 06:41:25

AFAIK,编辑器是根据文件扩展名选择的,并且没有机制可以根据文件内的特定内容对其进行自定义。

我看到 2 个选项

  • 创建自定义文本编辑器 来考虑您的自定义脚本标记(可能不值得努力)
  • 将您的 javascript 代码段放入外部文件中,在自定义脚本标记内使用 include 指令。

     <%@ include file="javascript.js" %> 
    

AFAIK, editors are chosen based on file extension, and there's no mechanism to customize this based on particular content inside the file.

I see 2 options

  • Creating a custom text editor to take into account your custom script tag (probably not worth the effort)
  • Put your javascript snippet in an external file, use the include directive inside your custom script tag.

        <%@ include file="javascript.js" %> 
    
兔小萌 2024-10-11 06:41:25

Eclipse 有一个模板功能,您可以在其中添加特定标签,该标签可用于所有 JSP 页面。

确保您已安装 Eclipse WTP (Web Tools Platform)

1.打开 Preferences 窗口 [ Select Window >偏好]
2.从菜单中展开Web选项,您可以在其中看到[CSS文件、HTML文件等。
3.选择JSP文件
4.选择编辑器
5.选择模板
6.在相应的窗格中,单击新建,然后可以轻松完成其余操作。

Eclipse has a template feature where in you can add specific tag ,which can be made available for all JSP pages.

Ensure you have installed Eclipse WTP ( Web Tools Platform )

1.Open Preferences window [ Select Window > Preferences ]
2.Expand Web Option from the menu, upon which you can see [ CSS Files,HTML Files etc..
3.Select JSP Files
4.Select Editor
5.Select Templates
6.In the corresponding pane , click New and from there rest can be easily done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文