JSP不会从数据库中正确显示值

时间:2014-06-05 10:00:40

标签: oracle jsp extjs utf-8 named-query

在mi web应用程序中,我有一个包含多于或少于符号选项的组合。当你打开组合看起来没问题,但是当你选择它时看起来不对劲(图1)。只有我想要在打开组合和选择时正确显示。

How combo shows

从Oracle DB中提取<符号。我使用UTF-8编码和ISO-8859-1,但不起作用。

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

提取值的表格

------------------
|ID_VALOR |  RTO |
|----------------|
|    1    | < 2h |
|    2    | < 8h |
------------------

查询

@NamedQueries({
        @NamedQuery(name = "RangoTemporal.getAll", query = "SELECT tt FROM RangoTemporal tt ORDER BY tt.id ASC")
})

编辑:添加了创建de dropdown的代码。 (extJS - Javascript)

        // creamos el combo de RTO
        var storeRTO = new Ext.data.SimpleStore({
            fields: [
               {name: 'ID_RTO'},                      
               {name: 'desRTO'}
            ]     
        });

        var dataRTO = [
            [
             '',
             '<bean:message key="label.gi.procesos.tabs.rtoProceso.automatico"/>'
            ]
            <logic:iterate name="gestionInventariosForm" property="tiposRangoML" id="rto" indexId="index">              
                <c:if test="${index >= 0}">, </c:if>                    
                [
                 '<bean:write name="rto" property="id"/>',
                 '<bean:write name="rto" property="descripcion"/>'
                ]
            </logic:iterate>
        ];

        // create the data store
        storeRTO.loadData(dataRTO);

        function dameComboRTO(){
            var comboRTO = new Ext.form.ComboBox({
                 store: storeRTO,
                 fieldLabel:'<bean:message key="label.gi.procesos.tabs.rtoProceso"/>',
                 displayField:'desRTO',
                 valueField: 'ID_RTO',
                 typeAhead: true,
                 forceSelection: true,
                 mode: 'local',
                 triggerAction: 'all',
                 emptyText:'',
                 selectOnFocus:true,
                 editable: true,
                 id: 'RTO_PROCESO',
                 <logic:notEqual value="0" name="gestionInventariosForm" property="proceso.id">             
                    value:'<bean:write name="gestionInventariosForm" property="proceso.rtoProceso.id" />',
                 </logic:notEqual>
                 <logic:equal value="0" name="gestionInventariosForm" property="proceso.id">                
                    value: '',  
                 </logic:equal>                      
                 disabled: false,
                 hiddenName: 'proceso.rtoProceso.id',
                 anchor:'80%',
                 listeners:{
                    select:{fn:function(combo){
                        document.getElementById( 'RTO_PROCESO_ID' ).value = combo.getValue();                               
                    }}
                 }
                 <logic:equal value="0" name="gestionInventariosForm" property="puedeEditar">,readOnly:true,fieldClass: 'NoEditable'</logic:equal>
            });
            return comboRTO;
        }

1 个答案:

答案 0 :(得分:0)

我在这里找到了答案http://www.sencha.com/forum/showthread.php?99826-Special-chars-problem-resolved-into-Combobox-TextField-Loading-Form-and-other-Apps

只有我覆盖了添加以下行的extjs配置:

htmlDecode : function(value){
     return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/"/g, '"').replace(/'/g, "'");
};

使用convert: function(v){return Ext.util.Format.htmlDecode(v);}修改代码。所以最后我的代码是:

        var storeRTO = new Ext.data.SimpleStore({
            fields: [
               {name: 'ID_RTO'},                      
               {name: 'desRTO', convert: function(v){return Ext.util.Format.htmlDecode(v);}}
            ]     
        });

现在看起来不错。

Combobox solved