【问题标题】:JSP dont show values correctly from DatabaseJSP 不能正确显示数据库中的值
【发布时间】:2014-06-06 18:13:23
【问题描述】:

在 mi web 应用程序中,我有一个组合选项,包括大于或小于符号。当你打开组合看起来不错,但当你选择它看起来不对(图 1)。只有我想在您打开组合和选择时都正确显示。

< 符号是从 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 下拉菜单的代码。 (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;
        }

【问题讨论】:

  • 这样显示是因为 JSP 使用了 <或>表示 符号..它只会像这样读取它..您可以毫无问题地继续您的工作..
  • 添加创建下拉列表的 JSP 代码 - 您从后端设置值的方式可能存在问题
  • 嗨,我添加了创建 de combobox 的代码

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


【解决方案1】:

我在这里创建了答案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);}}
            ]     
        });

现在看起来不错。

【讨论】:

    猜你喜欢
    • 2010-11-14
    • 2012-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-22
    • 2013-06-04
    • 2020-11-07
    相关资源
    最近更新 更多