Arabic data with jQuery-ajax and servlets

I'm actually trying to send arab data using jQuery ajax to Servlet

but when I try to retype this data on the page, it displays as

oo Β± Γ™Γ˜Β¬Γ˜ Β©

and this is my jQuery ajax code

        jQuery.ajax({
            url: "/SearchedCoursesGetter",
            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
            dataType: "text",
            data: {
                'searchKey':  'حديث'
            },
            success: function( data ) {
               document.write(data);
                }));
            }
        });

and this is the code in the java servlet

    response.setContentType("text/html;charset=UTF-8");
    request.setCharacterEncoding("UTF8");
    PrintWriter out = response.getWriter();
    out.print( request.getParameter("searchKey"));

can any body help me?

+3
source share
1 answer

Add this to the top of your JSP

<%@ page pageEncoding="UTF-8" %>

This will make the indirect response.setHeader("Content-Type", "text/html;charset=UTF-8")and response.setCharacterEncoding("UTF-8")in the JSP. Thus, the browser interprets the document (and therefore all the JS on it) as UTF-8.

You also need to make sure your JSP / JS files are saved as UTF-8. Check the editor settings and / or Save as, depending on the editor you are using.

, request.setCharacterEncoding("UTF-8") POST, GET. GET servletcontainer. , Tomcat URIEncoding="UTF-8" <Connector> /conf/server.xml.

. :

+3

All Articles