on 05-25-2007 9:14 AM
Hi Friends;
I have a servlet and I use
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//request.setCharacterEncoding("utf-8");
try {
dispatcher.forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
for forward page. But if i forward a page, this pages' encoding isnot working. But if i refresh page it works.
How can i handle this encoding.
Thanks replies
Hi Eray,
It really doesn't make any sense (exept in very specific, well, exceptional cases) to call setContentType and/or getWriter on the response object before doing a forward (neither does calling setCharacterEncoding on the request object usually makes sense);
request.getRequestDispatcher(page).forward(request, response);
should be sufficient. I assume you forward to a jsp page? In case you want to enforce the response encoding of the content of the jsp page to be UTF-8, you can use this page directive at the top of your jsp page:
<%@ page contentType="text/html; charset=UTF-8" %>
I don't know why it does work when you refresh the page, maybe your browser configuration is not correct (in IE: Page/View > Encoding > Auto-Select)?
Kind regards,
Sigiswald
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks for your reply but it didnt work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try the below code
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//request.setCharacterEncoding("utf-8");
try {
dispatcher.forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Regards,
Beevin.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.