dcsimg
JSF semi-randomly returns incorrectly encoded output. Fixed by hitting refresh.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Lon_Binder
Posted On:   Wednesday, April 30, 2008 09:10 AM

In a JSF page, I have a form in a view, that submits via an action commandlink... something like: ... ... It invokes the " run " method of the backing bean, which executes a POI/HSSF (excel) report, and streams it to the output stream. Something like (' BasePage ' is from AppFuse): public class ReportList extends BasePage implements Serializable { ... public String run() { HttpServletResponse response = getResponse(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=Summary.xls")   More>>

In a JSF page, I have a form in a view, that submits via an action commandlink... something like:


			


...



...


It invokes the " run " method of the backing bean, which executes a POI/HSSF (excel) report, and streams it to the output stream. Something like (' BasePage ' is from AppFuse):


			
public class ReportList extends BasePage implements Serializable {
...
public String run() {
HttpServletResponse response = getResponse();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=Summary.xls");
...
ServletOutputStream out = response.getOutputStream();
workbook.write(out);
out.flush();
out.close();
...
getFacesContext().responseComplete();
return null;
}



The first time I startup tomcat 6.0 and submit the form, the page returns incorrectly encoded characters, that look something like:


			
??X@?????????"???? ????????????1?????????????? A?r?i?a?l?1?????????????? ;_("$"* "-"_);_(@_) .?)?)??


Simply hitting 'refresh' resolves the issue and then it works fine (the form loads correctly, the browser "open or save as" dialog opens correct and the output excel document is perfect. If I leave the page and return, it generally works fine. And this only seems to happen once per app server startup.


I compared the HTTP headers of the correctly working case and the broken case, the only two differences are the " Content-Type ", which is " text/html " when broken and " text/html;charset=UTF-8 " when working. And the second is the response compression, which is " gzip " when working and " - " when broken. I disabled the gzip filter but that didn't help. I'm not sure how to adjust the character encoding.


Any advice would be greatly appreciated!


Thanks, Lon

   <<Less
About | Sitemap | Contact