Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Changing Eclipse Default Encoding to UTF-8 for JSP files

DZone's Guide to

Changing Eclipse Default Encoding to UTF-8 for JSP files

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

Try creating a new JSP file in your Eclipse and you’ll notice that the JSP page directive will have encoding something like:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

But for a better I18N and L10N support, it is recommended to follow UTF-8 encoding where ever possible. So, how do we change the default JSP file encoding to UTF-8 in eclipse? Simple. Just do these things:

  1. In Eclipse, go to Windows -> Preferences -> Web -> JSP Files
  2. Select UTF-8 encoding from the Encoding dropdown box there.

That’s it! And if you wonder how this change works, you can very well see that. In the same Preferences window, go to this location: Preferences -> Web -> JSP Files -> Editor -> Templates. Then in the right hand side, you’ll see a list of templates defined for JSP files.  And in a new JSP file template, you can see this code:

<%@ page language="java" contentType="text/html; charset=${encoding}" pageEncoding="${encoding}"%>

Here as you might have guessed, the ${encoding} will be replaced by whatever we set in the above step.

The same method can be used to change the default encoding type for other file types too (css, html).

From http://veerasundar.com/blog/2010/12/changing-eclipse-default-encoding-to-utf-8-for-jsp-files/

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}