I need to create an internationalized Web application by struts,mysql and hibernate. Each component Character Encoding is utf8. It runs well when I run a pure servlet to save 'Chinese Character' to database and load it from database. But when I implement it with struts action, the application can not save Chinese correctly. I really don't know why struts action can not work well. I am sure there is no difference between them. Is there anywhere to set character encoding for action? Please help!!!!! ------------------------------Pure Servlet ( It runs well) ------------------------------------------------------------- public class UtfTest extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8"); String description = request.getParameter("description"); description = (description == null?"":description.trim()); try{ ItemDAO itemDao = ItemDAO.getInstance(); Item item = new Item(); item.setDescription(description); itemDao.save(item); }catch(Exception e){ e.printStackTrace(); } response.sendRedirect("test.jsp"); } } ------------------------------Action for struts ---------------------------- public class TestAction extends Action{ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception { req.setCharacterEncoding("UTF-8"); String description = req.getParameter("description"); description = (description == null?"":description.trim()); try{ ItemDAO itemDao = ItemDAO.getInstance(); Item item = new Item(); item.setDescription(description); itemDao.save(item); // Determine which action forward should be returned return mapping.findForward("success"); }catch(Exception e){ } } }