Sunday, May 16, 2010

Internationalization tips for JSP

In order to display the complex script characters like Japanese, Chinese, etc in the browser window, the following changes need to be made at the beginning of each JSP file:

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


Wherever input controls are present, the following additional steps need to be taken:
Add the following code before reading any parameters in the previous JSP file:

request.setCharacterEncoding("UTF-8"); // Set the request encoding



While sending output to a browser:

response.setContentType ("charset=UTF-8");

1 comment:

  1. In case of struts :
    If that doesn't works, try adding

    request.setCharacterEncoding("UTF-8") in Action Form's reset method also. It might help.

    ReplyDelete