force eclipse to ignore character encoding attribu

2019-06-28 07:31发布

问题:

I'm working with a web framework that uses a dynamic character encoding in its html templates, like this:

<meta charset="${_response_encoding}">

The problem is when I try to edit this file in Eclipse, Eclipse thinks this is a literal encoding type, and thus refuses to open the file, saying:

"Unsupported Character Encoding" Character encoding "${_response_encoding}" is not supported by this platform.

Is there any way to tell Eclipse to stop trying to be "smart" (because it plainly isn't) and just show me the text? I've tried using "Open With... Text Editor" but still same result.

回答1:

Change the content type for HTML files:

Go to Windows -> preferences -> General -> Content types and change encoding (set them to utf-8) for all the file extensions you need.



回答2:

Choose "Other" and then select UTF-8. Then your template will render as normal.



回答3:

I had a similar problem, except I was receiving the error message when trying to save the document after changing the character encoding. I resolved the problem by doing the following in Eclipse before putting in the non-standard charset value:

  • Rename the file to have a non-HTML file extension.
  • Open the file using an editor other than the HTML one.
  • Change the charset value to the non-standard value you want.
  • Rename the file to have the original extension.
  • Open the file.
  • Follow the buttons and prompts to set the character encoding to the real encoding of the file.

After this, the file should still be usable while still having the non-standard charset value.



回答4:

If you're having Eclipse treat it like an HTML file, it is being smart. That's not a valid encoding name. Have you tried just templating the entire meta tag?



回答5:

(as mentioned in a comment) In Eclipse Indigo, when opening the file you see the Unsupported character encoding message along with a Set Encoding button. Us that button to set the UTF-8 encoding. Eclipse does not change the variable in the HTML file.

True, this is done on a file-by-file basis, however, in my project I import the same meta header file for every screen. Actually, I have only two files to setup (those that are logged in and those that are not).