2011-03-08 6 views
0

의 텍스트 영역에 표시합니다. 파일 (XML)을 찾고 읽는 방법을 Ext의 텍스트 영역에 표시 하시겠습니까?XML 파일을 업로드하고 읽고 Ext

  1. 클라이언트 측에서 기능을 수행 할 수 있습니까?
  2. XML 파일을 업로드하여 Java로 시도했지만 XML 문자열로 응답을 보내지 만 프런트 엔드에서 데이터를받을 수 없습니다 (예외 "반환 eval ("("+ json + ")") "extjs.all에서)?

    내선에서 내 코드


    var win = new Ext.Window({ 
        layout: 'fit', 
        title: 'XML Upload Window', 
        id: 'winFileRead', 
        resizable: false, 
        modal: true, 
        closeAction: 'close', 
        closable: true, 
        plain: true, 
        items: [{ 
         xtype: 'form', 
         id: 'frmFileRead', 
         fileUpload: true, 
         width: 500, 
         frame: true, 
         monitorValid: true, 
         autoHeight: true, 
         bodyStyle: 'padding: 10px 10px 0 10px;', 
         labelWidth: 50, 
         defaults: { 
          anchor: '95%', 
          allowBlank: false, 
          msgTarget: 'side' 
         }, 
         items: [{ 
          xtype: 'fileuploadfield', 
          id: 'verFileReadCmp', 
          emptyText: 'Select a File to import', 
          fieldLabel: 'File', 
          name: 'file', 
          buttonCfg: { 
           text: '', 
           iconCls: 'upload-icon' 
          } 
         }], 
         buttons: [{ 
          formBind: true, 
          text: 'Upload', 
          handler: function() { 
          var fp = Ext.getCmp('frmFileRead'); 
           if (fp.getForm().isValid()) { 
            fp.getForm().submit({ 
             url: 'viewXml.do', 
             params: {}, 
             method: 'POST', 
             waitMsg: 'Uploading your file...', 
             success: function(fp, o) { 
              if (Ext.decode(o.response.responseText).success) { 
               //Set the XML value to the textarea. Ext.getCmp('textareaXML').setValue(Ext.decode(o.response.responseText).message); 
              } else { 
               Util.showAlert('Err', Ext.decode(o.response.responseText).message); 
              } 
             }, 
             failure: function(response, options) { 
              Util.showAlert('Err', response.responseText); 
             }, 
             exception: function(a, b, c, d) {} 
            }); 
           } 
          } 
         }, 
         { 
          text: 'Reset', 
          handler: function() { 
           var fp = Ext.getCmp('frmFileRead'); 
           fp.getForm().reset(); 
         } 
        }] 
    }] 
    

    }); win.show();

    ***************************** 
    Java 
    **************************** 
    
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException, IOException 
    { 
        UploadFileTO uploadFileTO = (UploadFileTO) command; 
        List<XmlTO> al=new ArrayList<XmlTO>(); 
        Map<String,String> model = new HashMap<String,String>(); 
    
        MultipartFile file = uploadFileTO.getFile(); 
        InputStream inputStream = null; 
        String xmlString=""; 
        String xml=null; 
        if (file.getSize() > 0) { 
         inputStream = file.getInputStream(); 
    
         int readBytes = 0; 
         byte[] buffer = new byte[10000]; 
         while ((readBytes = inputStream.read(buffer, 0 , 10000))!=-1) 
         { 
          xml=new String(buffer, 0, readBytes); 
          xmlString=xmlString.concat(xml); 
         } 
         inputStream.close(); 
        } 
        if (!xmlString.equals("")){ 
         System.out.println(xmlString); 
         model.put("result", "{success:true, message: \""+xmlString+"\"}"); 
        }else{ 
         model.put("result", "{success:false, message: \"File upload error.\"}"); 
        } 
        return new ModelAndView("index", model); 
    } 
    
    **************************** 
    
    Exception message in JSON evaluation. 
    ******************************* 
    
    <TABLE width=400> 
        <P style="FONT: 13pt/15pt verdana">The XML page cannot be displayed 
         <P style="FONT: 8pt/11pt verdana">Cannot view XML input using style sheet. Please correct the error and then click the <A href="javascript:location.reload()" target=_self>Refresh</A> button, or try again later. 
          <HR> 
    
          <P 
           style="FONT: bold 8pt/11pt verdana"> 
           Invalid at the top level of the document. Error processing resource 'http://XXXXXXXX/viewXml.do'. 
          </P><PRE 
            style="LINE-HEIGHT: 12pt; FONT-VARIANT: normal; FONT-STYLE: normal; FONT-SIZE: 10pt; FONT-WEIGHT: normal" 
            ><FONT color=blue></FONT> 
           </PRE> 
         </P> 
        <TBODY> 
        </TBODY> 
    </TABLE> 
    

    1. 은 올바른 방법이 아닌 경우, 선호 또는 주요 브라우저 (인터넷 익스플로러, 파이어 폭스, 크롬)를 지원하는 가장 좋은 방법을 제공하십시오?
+0

반환되는 XML을 표시 할 수 있습니까? –

+0

UR 답장을 보내 주셔서 감사합니다. 3 점을 확인해 드리겠습니다. 위의 샘플 xml을 추가했습니다. 다시 한 번 감사드립니다. – vineth

답변

1

XML을 살펴볼 필요가 있습니다. 귀하의 코드가 좋은 것 같습니다. 다음은 문제를 해결하는 데 도움이되는 몇 가지 지침입니다.

  1. XML 형식이 잘못 되었습니까?
  2. 당신이 JSON 내부의 XML을 삽입하는 것을 기억하십시오, 당신은 단일 (') 또는 큰 따옴표 (")를 이스케이프해야합니다.
  3. 확인 브라우저가 viewXml.do
실행 한 후 올바른 JSON을 수신하는 경우 .

나는 문제가 하나 또는 세 가지의 조합에 의해 발생 확신 난 그냥 JSON을 다음과 같이 코드를 시도하고 잘 작동 :

는 XML 가져
{success:true, message: '<?xml version=\'1.0\' encoding=\'ISO-8859-1\'?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Test body..</body></note>'} 

에서는 ExtJS 텍스트 영역에 완벽하게 잘 렌더링 .

+0

답장을 보내 주셔서 감사합니다. 3 점을 확인해 드리겠습니다. 위에 샘플 XML을 추가했습니다. 다시 한 번 감사드립니다. – vineth

+0

그 형식으로 위의 xml을 보낼 수 없습니다. 그리고 differnt 속성을 가진 40000 줄의 큰 xml을 업로드해야하는 한 가지 더요. – vineth

관련 문제