我正在创建一个基于Web的java应用程序,我遇到了使应用程序国际化的问题。
当我使用我的EncodingFilter设置请求/响应编码时,数据库条目以奇怪的字符保存
??????
如果我删除了EncodnigFilter设置,数据库条目保存得很好,但我的JSP文件中的文本呈现为标记为@WebFilter(filterName="EncodingFilter", urlPatterns={"/*"})
public class EncodingFilter implements Filter{
private FilterConfig filterConfig=null;
private String encoding;
public void init(FilterConfig filterConfig)
{
this.filterConfig=filterConfig;
encoding = filterConfig.getInitParameter("requestEncoding");
if (encoding == null) encoding = "UTF-8";
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
if (null == request.getCharacterEncoding()) {
request.setCharacterEncoding(encoding);
}
response.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
public void destroy() {
this.filterConfig=null;
}
}
的问题
这是我的编码fitler
@WebServlet(name="LanguageController",urlPatterns={"/Language"})
public class LanguageController extends BaseControler{
private static final long serialVersionUID = 1L;
private ResourceBundle bundle;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doExecute(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doExecute(req, resp);
}
private void doExecute(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{
String refer = req.getHeader("referer");
if(refer == null)
refer = "index.jsp";
String param = req.getParameter("lang");
bundle = ResourceBundle.getBundle("messages",new Locale(param.toUpperCase()));
HttpSession session = req.getSession();
session.setAttribute(SessionKeys.LANGUAGE, bundle);
session.setAttribute(SessionKeys.LANGUAGE_STRING, param.toUpperCase());
resp.sendRedirect(refer);
}
}
这是我的语言控件,用于根据用户的请求更改语言
C:\blah\aeea2>for /L %f in (1,1,500) do @echo zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz >>testfile