Pesquisa personalizada

2008/08/05

How to change the file encoding from a specific JSP file from Netbeans 6.1?!

Unmodifiable file encoding

Ok. I don' know!
You try edit the JSP file, change from a encoding to other, close the file and open it again to see if the Netbeans recognizes the change, but sometimes, it fails! I think it's Netbeans bug...

The Netbeans doesn't allow you to change the file encoding directly by file Properties Window - the property Encoding is read only. But you can try to edit the JSP file and change the charset/encoding manually. Eg. you can change the occurrences from ISO-8859-1 to UTF-8, see:
<?xml version="1.0" encoding="ISO-8859-1"?>
<jsp:root version="2.1" 
        xmlns:f="http://java.sun.com/jsf/core" 
        xmlns:h="http://java.sun.com/jsf/html" 
        xmlns:jsp="http://java.sun.com/JSP/Page"
        xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
    <jsp:directive.page contentType="text/html;charset=ISO-8859-1" pageEncoding="ISO-8859-1"/>

Unfortunately, sometimes, this doesn't works and I don't know the reason... you can try to open the file using an text editor and saving it using another charset, or use some kind of file utility to convert it, but Netbeans yet doesn't recognize the new charset/encoding... Why? Netbeans saves some file attributes into ~/.netbeans/6.1/var/attributes.xml (I'm using Linux, but there is an equivalent file in other OSs, too). So, you must close the Netbeans IDE, open the attributes.xml using some editor, find the correspondent JSP filename entry and change the char set/encoding schema and you can open the Netbeans IDE again and to our surprise the Netbeans, finally, recognize the encoding change. Don't forgot to change charset/encoding from the JSP file, also. Bellow is an entry from the attributes.xml with the charset attribute to be changed:

<fileobject name="|home|usuario|dev|projects|eletron|rastreador|TrilhaWeb|web|monitor|IndexX.jsp">
        <attr name="encoding" stringvalue="ISO-8859-1"/>
        <attr name="jsfjsp" boolvalue="true"/>
</fileobject>


Good luck!

Labels: ,

1 Comments:

Blogger Rafael Santini said...

In the Windows, the attributes.xml is located in C:\Documents and settings\"user"\.netbeans\"version"\var. But I can't see in the attributes.xml the file that I'm trying change the encoding. The date of this file is not changed after I edit and save a file in NetBeans.

02 July, 2009 19:43  

Post a Comment

<< Home