Added content type header to HTML responses to force UTF-8.
This commit is contained in:
parent
1a95b8fdf6
commit
8fee7d3802
2 changed files with 34 additions and 1 deletions
|
@ -55,7 +55,6 @@ public class EssayistServletContextListener extends GuiceServletContextListener
|
|||
poolProperties.setUrl(properties.getProperty("db.url"));
|
||||
poolProperties.setDriverClassName(properties.getProperty("db.driverClassName"));
|
||||
poolProperties.setInitialSize(Integer.parseInt(properties.getProperty("db.initialSize")));
|
||||
poolProperties.setJdbcInterceptors(properties.getProperty("db.jdbcInterceptors"));
|
||||
|
||||
DataSource dataSource = new DataSource(poolProperties);
|
||||
|
||||
|
@ -88,6 +87,7 @@ public class EssayistServletContextListener extends GuiceServletContextListener
|
|||
serve("/write").with(NewEssayServlet.class);
|
||||
serveRegex("/(.*)/essays").with(EssaysServlet.class);
|
||||
serveRegex("/(.*)/essay/(.*)").with(EssayServlet.class);
|
||||
filter("/*").through(Utf8Filter.class);
|
||||
}
|
||||
}, new AbstractModule() {
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.moandjiezana.tent.essayist.config;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Singleton
|
||||
public class Utf8Filter implements Filter {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
if (!"application/json".equals(req.getHeader("Accept"))) {
|
||||
response.setContentType("text/html;charset=utf-8");
|
||||
}
|
||||
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {}
|
||||
|
||||
@Override
|
||||
public void destroy() {}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue