Я пытался с Java, загрузив файл XML, прочитав его и отправив ответ в виде строки XML, но я не могу получить данные в интерфейсе (возникает исключение «return eval (»)("+ json +") ")" в extjs.all
)?
Мой код в Ext
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 al=new ArrayList();
Map model = new HashMap();
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.
*******************************
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
Invalid at the top level of the document. Error processing resource 'http://XXXXXXXX/viewXml.do'.