本文介绍了JSP不支持UTF-8编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图在我的jsp页面中显示中文字符时,它将显示垃圾字符。我做错了什么?我已经包括下面的行到我的顶部的jsp,即使这个问题没有得到修复。

 <%@ contentType =text / html; charset = UTF-8pageEncoding =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 / javascriptlanguage =javascript
src =/ integration / r5 / hpr / js / jquery-1.3.2.js>< ; / script>

< script language =JavaScript>
// Javascript代码在这里...
< / 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.tldprefix =worklist%>
< link rel =stylesheettype =text / csshref =/ integration / r5 / hpr / css / homepages-v5.css/>
<%
地图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 =javacontentType =text / html; charset = UTF-8
pageEncoding =UTF-8%>
< META http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title>选择任务< / title>
< / head>
< body>
<%
}
%>
< br />
< form STYLE =display:inline; method =POSTname =SelectTask
action =<%= request.getContextPath()%> / SelectTask>

< input type =hiddenname =methodid =methodvalue =''/> < input
type =hiddenname =methodid =methodvalue =''/> < input
type =hiddenname =taskIdid =taskIdvalue ='<%= taskId%>'/>

<! - jQuery Ajax东西为新的创建任务的方式,页面不刷新时选择组织 - >
< 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');
//超时设置30秒
ajax_timeout = setTimeout(
function(){
// alert('Request was taking 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(){
});
//超时调用
if(ajax_timeout2){
clearTimeout(ajax_timeout2);
}
}
});

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

});

//业务流程选择框
$(#orgId)。change(function(){
$ .ajax({
type:GET,
url:servletContextPath
+/ OrganizationProcessHandler,
data:{
orgId:$ params
},
cache:false,
beforeSend:function(){
//alert(this.url =='myUrl');
//超时设置30秒
ajax_timeout = setTimeout(
function b $ b // alert('Request is taking long long。');
},
30000);
//
},
success:function(xmlResponse){
$(xmlResponse).find('ITEMS')
.each b $ b});
//超时调用
if(ajax_timeout){
clearTimeout(ajax_timeout);
}
//
},
complete:function(){
//alert(this.async == true);
}
})

});

//任务组处理程序
$(#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');
//超时设置30秒
ajax_timeout = setTimeout(
function(){
// alert('Request is taking long time。');
}
30000);
//
},
success:function(xmlResponse){
$(xmlResponse).find('ITEMS')
.each b $ b // alert(Task Group ===+ valTxt);
$('< option value ='+ valTxt +'>'
+ labelTxt
+'< / option>')
.appendTo(#taskGrpId);
});
//超时调用
if(ajax_timeout){
clearTimeout(ajax_timeout);
}
//

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

//任务处理程序
$(#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 long time。');
},
30000);
//
},
success:function(
xmlResponse){
$(xmlResponse).find('ITEMS')
.each (){
});
//超时调用
if(ajax_timeout){
clearTimeout(ajax_timeout);
}
//

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

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

<! - 提交时的图层 - >
< script type =text / javascript>
$(document)
.ready(
function(){
$(#Save)。 taskConfigId = document
.getElementById(taskConfigId)。value;
if(taskConfigId == null
|| taskConfigId ==''
|| taskConfigId == -4
|| taskConfigId.length == 0){
alert('请选择任务');
} else {
getBackToTaskCreationForm();
//获取屏幕高度和宽度
var maskHeight = $(document).height();
var maskWidth = $(window).width();

// alert(taskConfigId ==+ taskConfigId);
//设置高度和宽度以掩盖整个屏幕
$('#mask')。css({
'width':maskWidth,
'height' :maskHeight
});

// transition effect
}
});

});
< / script>





-css



代码:



 <! -  endless  - > 

< table width =100%border =0class =HeaderPanecellpadding = 0
cellspacing = 0 height =44bordercolor =#000000>
< tr width =100%>
< td width =100%class =customContentText>< strong>组织:< / strong>
< select id =orgIdname =orgId>
< option VALUE =' - 1'> ------------选择组织
------------< / option>
< / select>< / td>
< / tr>
< tr width =100%>
< td width =100%class =customContentText>
< p id =loadingstyle =margin-left:80px;>
< img src =/ integration / r5 / hpr / images / ajax-loader.gif
alt =loading/> < br />请稍候....
< / p>
< p id =done>< / p>


< p id =warningstyle =margin-left:80px;>
< img src =img / warnsign.gifalt =warningwidth =16height =16/>
< br />您的请求已超时。请再试一次。如果此
条件继续,请与您的管理员联系。
< / p> < br />
< / td>
< / tr>
< tr width =100%>
< td width =100%class =customContentText>
< table width =100%align =centerclass =HeaderPaneid =table1>
-------
< / table>
< / td>
< / form>
< / table>

<! - 掩码覆盖整个屏幕 - >
< div id =mask>
< center>
< img src =/ integration / r5 / hpr / images / ajax-loader.gifalt =loading/>
< br />
< font color =Whitesize =4>请稍候....< / font>
< / center>
< / div>


<%
if(taskId == null || taskId.trim()。equals()){
%>

< / TD>
< / TR>
< / TABLE>
< / TD>
< / TR>
< / TABLE>
< jsp:include page =/ Footer.jsp/>
<%
} else {
%>
< / body>
< / html>
<%
}
%>

web.xml:

 <?xml version ='1.0'encoding ='GBK'?> 
< web-app xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml / ns / javaee http://java.sun.com/xml/ns /javaee/web-app_2_5.xsd
version =2.5xmlns =http://java.sun.com/xml/ ns / javaee>

< / web-app>

Servlet:

 code> public class OrganizationLoadServlet extends HttpServlet {
private static Logger log = Logger.getLogger(OrganizationLoadServlet.class);

public void doGet(HttpServletRequest请求,HttpServletResponse响应)throws ServletException,IOException {
HttpSession session = request.getSession();

组织[] orgs =(组织[])session.getAttribute(WorklistappConstants.SESS_ATTR_PREFS_ORGANIZATIONS);

if(orgs == null){
orgs = getFilteredOrgs(request);
session.setAttribute(WorklistappConstants.SESS_ATTR_PREFS_ORGANIZATIONS,orgs);
}

log.info(Before:+ response.getCharacterEncoding()); //这里我得到iso-8859-1
StringBuffer sb = new StringBuffer();
String dislayName = null;
for(int i = 0; i Organization org = orgs [i];
dislayName = org.getOrgDisplayName();

sb.append(< ITEMS>);
sb.append(< LABEL><![CDATA [+ dislayName +]]>< / LABEL>);
sb.append(< VALUE><![CDATA [+ org.getOrgId()+]]>< / VALUE>);
sb.append(< / ITEMS>);
}

response.setContentType(text / xml);
response.setHeader(Cache-Control,no-cache);
response.getWriter()。write( log.info(After:+ response.getCharacterEncoding()); //这里我得到iso-8859-1

}

public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException {
this.doGet(request,response);
}

private Organization [] getFilteredOrgs(HttpServletRequest request){
// code
return orgs;

}

private Organization [] filterOrganizationsByUserOrgs(Organization [] orgs,List< Long> userOrgIdList){
// code

return filteredOrgs;
}

private List< Long> getUserOrgIdList(String userId)throws Exception {
// code

return userOrgIdList;
}

private String getUserID(HttpServletRequest请求)throws IOException {

//代码
return wfCtx.getUser();
}

}



请参阅Servlet类中的注释。如果我将 iso-8859-1 更改为 utf-8 ,那么我无法访问应用程序。

这里,问题是 CDATA c>。在Servlet中,我们使用 iso-8859-1 以xml格式发送xml响应。当我们尝试使用 UTF-8 时,不生成xml格式的响应。因此,不是从servlet发送xml响应到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());



JSP



  $('#orgId')。html(< option value = \'-1\'> ------------选择组织------ ------< / option>+ xmlResponse); 


When I am trying to display chineese characters in my jsp page, then it will display junk characters. What was the wrong I did? I have included the below line to my jsp on the top, even the issue is not getting fixed.

<%@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
                                                                    });

                                                    //transition effect
                                                                                            }
                                            });

                        });
    </script>

-css

code here:

    <!-- endless -->

    <table width="100%" border="0" class="HeaderPane" cellpadding=0
        cellspacing=0 height="44" bordercolor="#000000">
        <tr width="100%">
            <td width="100%" class="customContentText"><strong>Organization:</strong>
                <select id="orgId" name="orgId">
                    <option VALUE='-1'>------------ Select Organization
                        ------------</option>
            </select></td>
        </tr>
        <tr width="100%">
            <td width="100%" class="customContentText">
                <p id="loading" style="margin-left: 80px;">
                    <img src="/integration/r5/hpr/images/ajax-loader.gif"
                        alt="loading" /> <br />Please wait....
                </p>
                <p id="done"></p>


                <p id="warning" style="margin-left: 80px;">
                    <img src="img/warnsign.gif" alt="warning" width="16" height="16" />
                    <br />Your request has timed out. Please try again. If this
                    condition continues, please contact your administrator.
                </p>  <br />
            </td>
        </tr>
        <tr width="100%">
            <td width="100%" class="customContentText">
                <table width="100%" align="center" class="HeaderPane" id="table1">
                    -------
                </table>
            </td>
            </form>
    </table>

    <!-- Mask to cover the whole screen -->
    <div id="mask">
        <center>
            <img src="/integration/r5/hpr/images/ajax-loader.gif" alt="loading" />
            <br />
            <font color="White" size="4"> Please wait....</font>
        </center>
    </div>


    <%
        if (taskId == null || taskId.trim().equals("")) {
    %>

                </TD>
            </TR>
        </TABLE>
    </TD>
</TR>
</TABLE>
<jsp:include page="/Footer.jsp" />
<%
        } else {
%>
</body>
</html>
<%
        }
%>

web.xml:

<?xml version = '1.0' encoding = 'GBK'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns  /javaee/web-app_2_5.xsd"
     version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">

</web-app>

Servlet:

public class OrganizationLoadServlet extends HttpServlet {
private static Logger log = Logger.getLogger(OrganizationLoadServlet.class);

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session = request.getSession();

    Organization[] orgs = (Organization[])session.getAttribute(WorklistappConstants.SESS_ATTR_PREFS_ORGANIZATIONS);

    if (orgs == null) {
        orgs = getFilteredOrgs(request);
        session.setAttribute(WorklistappConstants.SESS_ATTR_PREFS_ORGANIZATIONS, orgs);
    }

    log.info("Before: " + response.getCharacterEncoding());//Here I am getting "iso-8859-1"
    StringBuffer sb = new StringBuffer();
    String dislayName = null;
    for (int i = 0; i < orgs.length; i++) {
        Organization org = orgs[i];
        dislayName = org.getOrgDisplayName();

        sb.append("<ITEMS>");
        sb.append("<LABEL><![CDATA[" + dislayName + "]]></LABEL>");
        sb.append("<VALUE><![CDATA[" + org.getOrgId() + "]]></VALUE>");
        sb.append("</ITEMS>");
    }

    response.setContentType("text/xml");
    response.setHeader("Cache-Control", "no-cache");
    response.getWriter().write("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><ITEM>" + sb.toString() + "</ITEM>");
    log.info("After: " + response.getCharacterEncoding());//Here I am getting "iso-8859-1"

}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doGet(request, response);
}

private Organization[] getFilteredOrgs(HttpServletRequest request) {
//code
return orgs;

}

private Organization[] filterOrganizationsByUserOrgs(Organization[] orgs, List<Long> userOrgIdList) {
    //code

    return filteredOrgs;
}

private List<Long> getUserOrgIdList(String userId) throws Exception {
//code

    return userOrgIdList;
}

private String getUserID(HttpServletRequest request) throws IOException {

//code
    return wfCtx.getUser();
}

}

Please see the comments in Servlet class. If I change iso-8859-1 to utf-8, then I am not able to access application. What was the wrong in that?

解决方案

Here, the problem is with CDATA. In Servlet, we used iso-8859-1 for sending xml response in xml format. When we tried with UTF-8, the response in xml format not being generated. So instead of sending xml response from servlet to jsp, we used to send that response as html format and displayed as html response on jsp page. This helps in fixed my issue.

In Servlet we modified

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());

JSP

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

这篇关于JSP不支持UTF-8编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:46