Hi,
In the struts action you are setting character encoding on 'request'
object req ,it however needs to be on 'response' ie res.
Deepesh.
public class TestAction extends Action{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) throws Exception {
req.setCharacterEncoding("UTF-8"); // this should be
res.setCharacterEncoding("UTF-8");
String description = req.getParameter("description");
description = (description == null?"":description.trim());
try{
ItemDAO itemDao = ItemDAO.getInstance();
Item item = new Item();
----- Original Message -----
From: "Tony Lu" <[EMAIL PROTECTED]>
To: <user@struts.apache.org>
Sent: Tuesday, October 18, 2005 11:14 AM
Subject: So boring issues about character encoding in action ......
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){
}
}
}
--------------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.12.2/139 - Release Date: 10/17/2005
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]