My name is Veera. I'm a full stack web developer. I have founded http://www.timethetask.com and currently working on my next product. Veera is a DZone MVB and is not an employee of DZone and has posted 33 posts at DZone. You can read more from them at their website. View Full User Profile

Changing Eclipse Default Encoding to UTF-8 for JSP files

12.08.2010
| 15065 views |
  • submit to reddit

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/

Published at DZone with permission of Veera Sundar, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Ignacio Cougil Jares replied on Wed, 2010/12/08 - 12:35pm

That's a great tip! Always I've to change the workspace configuration for different projects and yes, every project has its own encoding and represents problems creating new JSPs. Thanks a lot!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.