UTF-8 编码不支持 JSP

use*_*341 5 jsp servlets jdeveloper utf-8 character-encoding

当我试图在我的 JSP 页面中显示中文字符时,它会显示垃圾字符。

我做错了什么?

我在顶部的 JSP 中包含了以下行,即使是现在,问题也没有得到解决:

<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>

<%@ page import="java.util.*"%>
<%@ page import="com.hp.sales.om.workflow.c2c.config.model.Organization"%>
<%@ page import="com.hp.sales.om.workflow.c2c.config.model.ClassificationL1"%>
<%@ page import="com.hp.sales.om.workflow.c2c.config.model.ClassificationL2"%>
<%@ page import="com.hp.sales.om.workflow.c2c.config.model.TaskConfig"%>

 <script type="text/javascript" language="javascript"
src="/integration/r5/hpr/js/jquery-1.3.2.js"></script>

<script language="JavaScript">
//Javascript code here...
</script>

<%
String taskId = (String) request.getAttribute("taskId");
if (taskId == null || taskId.trim().equals("")) {
    taskId = ""; 
%>
<jsp:include page="/Header.jsp" />
<%@ taglib uri="http://xmlns.oracle.com/bpel/workflow/worklist-taglib.tld" prefix="worklist"%>
<link rel="stylesheet" type="text/css" href="/integration/r5/hpr/css/homepages-v5.css" />
<%
Map links = new LinkedHashMap();
    links.put("Select Task", request.getContextPath()
            + "/SelectTask");
    String disableCondition = "";
%>

<worklist:navLinks linkMap="<%=links%>" styleClass="customBreadCrumbNav"
separator=" > " prefixHTML="<strong>" suffixHTML="</strong>"
disableConditionBasedOn="<%=disableCondition%>" />
<!-- border table -->
 <TABLE WIDTH="100%" BORDER="0">
 <TR>
     <TD>
        <TABLE WIDTH="100%" BORDER="1">
             <TR>
                        <TD>
                            <%
                                } else {
                             %>
                    <html>
 <head>
 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
 <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Select Task</title>
 </head>
 <body>
<%
    }
%>
<br />
<form STYLE="display: inline;" method="POST" name="SelectTask"
    action="<%=request.getContextPath()%>/SelectTask">

    <input type="hidden" name="method" id="method" value='' /> <input
        type="hidden" name="method" id="method" value='' /> <input
        type="hidden" name="taskId" id="taskId" value='<%=taskId%>' />

    <!-- jQuery Ajax stuff for new way of create task, page not be refresh when choose organization -->
    <script type="text/javascript">
     var servletContextPath = <%=request.getContextPath()%>
        ";"
        $(document)
                .ready(
                        function() {

                            $(window).load(function() {
                                                $.ajax({
                                                            url : servletContextPath
                                                                    + "/OrganizationLoadServlet",
                                                            cache : false,
                                                            beforeSend : function() {
                                                                //alert(this.url == 'myUrl');
                                                                //timeout setting 30second
                                                                ajax_timeout = setTimeout(
                                                                        function() {
                                                                            //alert('Request is taking a long time.');
                                                                                                            },
                                                                        30000);
                                                                //
                                                            },
                                                            success : function(
                                                                    xmlResponse) {
                                                                var count = 0;
                                                                $(xmlResponse)
                                                                        .find('ITEMS')
                                                                        .each(function() {
                                                                                    count++;
                                                                                });
                                                                if (count == 1) {
                                                                    $(xmlResponse).find('ITEMS')
                                                                            .each(function() {
                                                                                                                                });
                                                                    $.ajax({
                                                                                type : "GET",
                                                                                url : servletContextPath
                                                                                        + "/OrganizationProcessHandler",
                                                                                data : {
                                                                                    orgId : $params
                                                                                },
                                                                                cache : false,
                                                                                beforeSend : function() {
                                                                                    ajax_timeout2 = setTimeout(
                                                                                            function() {
                                                },
                                                                                            30000);
                                                                                },
                                                                                success : function(xmlResponse) {
                                        $(xmlResponse).find('ITEMS')
                                                                                            .each(function() {
                                                        });
                                                                                    //timeout calling
                                                                                    if (ajax_timeout2) {
                                                                                        clearTimeout(ajax_timeout2);
                                                                                    }
                                                                                }
                                                                            });

                                                                } else {
                                                                    $(xmlResponse).find('ITEMS')
                                                                            .each(function() {
                                                                                    });
                                                                }
                                                                //timeout calling
                                                                if (ajax_timeout) {
                                                                    clearTimeout(ajax_timeout);
                                                                }
                                                                //
                                                            },
                                                            complete : function() {
                                                                //alert(this.async == true);
                                                            }
                                                        });

                                            });

                            //Business Process choicebox
                            $("#orgId").change(function() {
                                                $.ajax({
                                                            type : "GET",
                                                            url : servletContextPath
                                                                    + "/OrganizationProcessHandler",
                                                            data : {
                                                                orgId : $params
                                                            },
                                                            cache : false,
                                                            beforeSend : function() {
                                                                //alert(this.url == 'myUrl');
                    //timeout setting 30second
                                                                ajax_timeout = setTimeout(
                                                                        function() {
                                                                            //alert('Request is taking a long time.');
                            },
                                                                        30000);
                                                                //
                                                            },
                                                            success : function(xmlResponse) {
                                                                $(xmlResponse).find('ITEMS')
                                                                        .each(function() {
                                                                                                                                                                        });
                                                                //timeout calling
                                                                if (ajax_timeout) {
                                                                    clearTimeout(ajax_timeout);
                                                                }
                                                                //
                                                            },
                                                            complete : function() {
                                                                //alert(this.async == true);
                                                            }
                                                        });

                                            });

                            //Task Group handler
                            $("#processId").change(function() {
                                                if ($processId.length != 0) {
                                                    $.ajax({
                                                                type : "POST",
                                                                url : servletContextPath
                                                                        + "/TaskGroupsForOrgAndProcessHandler",
                                                                data : {
                                                                    orgId : $orgId,
                                                                    processId : $processId
                                                                },
                                                                cache : false,
                                                                beforeSend : function() {
                                                                    //alert(this.url == 'myUrl');
                        //timeout setting 30second
                                                                    ajax_timeout = setTimeout(
                                                                            function() {
                                                                                //alert('Request is taking a long time.');
                                                                            },
                                                                            30000);
                                                                    //
                                                                },
                                                                success : function(xmlResponse) {
                                                                    $(xmlResponse).find('ITEMS')
                                                                            .each(function() {
                                                                                        //alert("Task Group === "+valTxt);
                                                                                        $('<option value="' + valTxt + '">'
                                                                                                        + labelTxt
                                                                                                        + '</option>')
                                                                                                .appendTo("#taskGrpId");
                                                                                    });
                                                                    //timeout calling
                                                                    if (ajax_timeout) {
                                                                        clearTimeout(ajax_timeout);
                                                                    }
                                                                    //

                                                                },
                                                                complete : function() {
                                                                    //alert(this.async == true);
                                                                }
                                                            });
                                                }
                                            });

                            //Task handler
                            $("#taskGrpId").change(function() {
                                                if ($taskGrpId.length != 0) {
                                                    $.ajax({
                                                                type : "POST",
                                                                url : servletContextPath
                                                                        + "/TaskConfigsHandler",
                                                                data : {
                                                                    orgId : $orgId,
                                                                    processId : $processId,
                                                                    taskGrpId : $taskGrpId
                                                                },
                                                                cache : false,
                                                                beforeSend : function() {
                                                                    ajax_timeout = setTimeout(
                                                                            function() {
                                                                                //alert('Request is taking a long time.');
                                                                            },
                                                                            30000);
                                                                    //
                                                                },
                                                                success : function(
                                                                        xmlResponse) {
                        $(xmlResponse).find('ITEMS')
                                                                            .each(function() {
                                                                                                                                                                            });
                                                                    //timeout calling
                                                                    if (ajax_timeout) {
                                                                        clearTimeout(ajax_timeout);
                                                                    }
                                                                    //

                                                                },
                                                                complete : function() {
                                                                    //alert(this.async == true);
                                                                }
                                                            });
                                                }
                                            });

                        });
    </script>
    <!-- endless -->

    <!-- Layer for during do submition -->
    <script type="text/javascript">
        $(document)
                .ready(
                        function() {
                            $("#Save").click(
                                            function() {
                                                var taskConfigId = document
                                                        .getElementById("taskConfigId").value;
                                                if (taskConfigId == null
                                                        || taskConfigId == ''
                                                        || taskConfigId == -4
                                                        || taskConfigId.length == 0) {
                                                    alert('Please select task');
                                                } else {
                                                    getBackToTaskCreationForm();
                                                    //Get the screen height and width
                                                    var maskHeight = $(document).height();
                                                    var maskWidth = $(window).width();

                                                    //alert("taskConfigId== " +taskConfigId);
                                                    //Set heigth and width to mask to fill up the whole screen
                                                    $('#mask').css({
                                                                        'width' : maskWidth,
                                                                        'height' : maskHeight
                                                                    });

                       

use*_*341 1

在这里,问题在于CDATA. 在 Servlet 中,我们用于iso-8859-1以 xml 格式发送 xml 响应。当我们尝试使用 时UTF-8,未生成 xml 格式的响应。因此,我们不是将 xml 响应从 servlet 发送到 jsp,而是以 html 格式发送该响应并在 jsp 页面上显示为 html 响应。这有助于解决我的问题。

在Servlet中我们修改

sb.append("<option value="+org.getOrgId()+">"+dislayName+"</option>");
    response.setContentType("text/html;charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");

    response.getWriter().write(sb.toString());
Run Code Online (Sandbox Code Playgroud)

联合应用程序

$('#orgId').html("<option value=\'-1\'>------------ Select Organization ------------</option>"+xmlResponse);
Run Code Online (Sandbox Code Playgroud)