3

My jsp page has encoding as follows :

<%@ page
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
%>

<%

response.setHeader("Cache-control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
%>

javascript code printing greek characters well in firebug following is the code :

function save() {
console.log(document.editDistributionListForm.elements['name'].value); //this line prints greek characters
  document.editDistributionListForm.elements['subAction'].value='submit';
  document.editDistributionListForm.submit();
}

when 'name' value as above is sent to the struts action, the string is not printing greek characters instead it prints ????????????????

Greek Characters entered were : αβγδεζηθ

Struts Bean (Sample code) :

public void setName(String name) {
                this.name = name;
        }

        public String getName() {
                return name;
        }

Struts Action (Sample code) :

protected ActionForward updateList(ActionMapping mapping,
                                HttpServletRequest request,
                                EditListForm form)
                        throws CannotOverwriteExistingListException, EmptyListException,
                                ListUpdateException {
log.debug("form.getName :: "+form.getName()); //this line when printed prints (???) 

}

when data is sent from html to java i.e. from browser to server the string gets converted from greek to ???? what i am doing wrong. I am not able to identify what i am missing .. .

Please help.

vermaraj
  • 634
  • 3
  • 10
  • 34

1 Answers1

1

There are no Greek characters in UTF-8.

I think you should reprogram your program to make it print UTF-16 characters (which do include Greek characters). (Change the page encoding from UTF-8 to UTF-16)

Honesty
  • 150
  • 2
  • 11
  • I think it should work well. Let me make you understand the things. We have Admin application and User Application they both have different war files(Application is deployed to tomcat server). But they share java class files. When i make changes in Admin (for example the name property) and give Greek characters to it and save it. The application also reflects in User application because it shows Greek characters as well for the same property. But when changed from User Application, they show ???? characters.From this point i can say that the page encoding is ok for both. but issue in java. – vermaraj Jun 27 '14 at 04:09
  • I still think you should change the charset and pageEncoding variables, just to be on the safe side. The two lines of code: response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); only take in UTF-8 characters... and are supposed to only print out UTF-8 characters. All I'm saying is that you should try it out and see if it works. – Honesty Jun 27 '14 at 17:18
  • I followed this link and it worked fine. http://stackoverflow.com/a/138950/3493471 I think you should recommend other for this also. – vermaraj Jul 02 '14 at 12:41