Displaying UTF-8 Characters in resource response

The portlet specification says that when resource request is made the portal only acts as proxy and as a result you have more control on the HTTP request, response, you can set additional headers do things that you cannot in the render method, this issue also has some disadvantages, For example if you want to return UTF-8 characters in the doView() method you dont have to do any thing special but if you want to return same UTF-8 characters through serveResource method then you will have to call PortletResponse.setCharacterEncoding("UTF-8")

I do have this sample portlet which displays some Chinese characters in both doView() and serveResource() method the characters are displayed right in the view mode markup but it displays funny characters while displaying response of the resource URL

When i looked at the HTTP headers of response, it seems that when portal returns response it automatically sets character encoding to UTF-8 irrespective of if your setting UTF-8 characters or not but when you return markup from serveResource , character encoding is not set by portal, so i had to change my code and set the character encoding manually and now it works

public class ServeResourceUTF8Portlet extends GenericPortlet{
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
getPortletContext().getRequestDispatcher("/view.jsp").include(request, response);
public void serveResource(ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {

This is how the response looks like after setting character encoding manually, as you can see it adds the information to contentType header


srjwebsolutions said...

We are leading responsive website designing and development company in Noida.
We are offering mobile friendly responsive website designing, website development, e-commerce website, seo service and sem services in Noida.

Responsive Website Designing Company in Noida
Website Designing Company in Noida
SEO Services in Noida
SMO Services in Noida

Vikas Chaudhary said...

Battery Mantra is Authorized exide car battery dealer in Noida and Greater Noida. We are providing our service in Indirapuram, Delhi, Ashok Nagar.

Exide Battery Dealer in Noida
Battery Dealer in Noida
Authorized Battery Dealer in Noida
Car Battery Dealer in Noida
Car Battery Dealer
Exide Battery Dealer

EG MEDI said...

Egmedi.com is online medical store pharmacy in laxmi nagar Delhi. You can Order prescription/OTC medicines online.
Cash on Delivery available. Free Home Delivery

Online Pharmacy in Delhi
Buy Online medicine in Delhi
Online Pharmacy in laxmi nagar
Buy Online medicine in laxmi nagar
Onine Medical Store in Delhi
Online Medical store in laxmi nagar
Online medicine store in delhi
online medicine store in laxmi nagar
Purchase Medicine Online
Online Pharmacy India
Online Medical Store