我已经制作了ckeditor插件将doc文件转换为html,该文件通过servlet与ajax上传并转换为html。但是我没有得到servlet的html响应。我在结果中得到了相同的jsp页面。
这是Servlet代码。
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// HttpSession
response.setContentType("text/html"); // session;
if (!ServletFileUpload.isMultipartContent(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN,
"only multipart requests are allowed");
return;
}
WebappContext webappContext = WebappContext.get(getServletContext());
ServletFileUpload fileUpload = webappContext.getFileUpload();
OfficeDocumentConverter converter = webappContext
.getDocumentConverter();
String outputExtension = FilenameUtils.getExtension(request
.getRequestURI());
FileItem uploadedFile;
try {
uploadedFile = getUploadedFile(fileUpload, request);
// FileHandler.checkForValidExtn(uploadedFile);
} catch (FileUploadException fileUploadException) {
throw new ServletException(fileUploadException);
}
if (uploadedFile == null) {
throw new NullPointerException("uploaded file is null");
}
String inputExtension = FilenameUtils.getExtension(uploadedFile
.getName());
String baseName = FilenameUtils.getBaseName(uploadedFile.getName());
// File fileFolder=new File(getServletContext().getRealPath("/")
// +"images");
// fileFolder.mkdir();
// File inputFile=new File(fileFolder+"\\"+ baseName + "." +
// inputExtension);
File inputFile = new File(getServletContext().getRealPath("/")
+ baseName + "." + inputExtension);
writeUploadedFile(uploadedFile, inputFile);
File outputFile = new File(getServletContext().getRealPath("/")
+ baseName + "." + "html");
// File outputFile=new File(fileFolder+"\\"+ baseName + "." + "html");
// outputFile.mkdirs();
System.out.println("input file path:" + inputFile.getAbsolutePath());
System.out.println("outPut file path:" + outputFile.getAbsolutePath());
try {
// DocumentFormat outputFormat = converter.getFormatRegistry()
// .getFormatByExtension(outputExtension);
long startTime = System.currentTimeMillis();
converter.convert(inputFile, outputFile);
long conversionTime = System.currentTimeMillis() - startTime;
logger.info(String.format(
"successful conversion: %s [%db] to %s in %dms",
inputExtension, inputFile.length(), outputExtension,
conversionTime));
} catch (Exception exception) {
logger.severe(String.format(
"failed conversion: %s [%db] to %s; %s; input file: %s",
inputExtension, inputFile.length(), outputExtension,
exception, inputFile.getName()));
throw new ServletException("conversion failed", exception);
} finally {
inputFile.delete();
}
PrintWriter out = response.getWriter();
out.println("<b>File Sent to server</b>");
out.close();
}
以下是sendi文件到服务器的代码javascript代码。
CKEDITOR.dialog.add( 'uploadDoc', function( editor )
{ var dialougeDefination =
{ title: editor.lang.uploadDoc.labelName,
resizable: CKEDITOR.DIALOG_RESIZE_BOTH,
minWidth: 250,
minHeight: 50,
onOk: function()
{ if(document.getElementById("flFileBrowser").value == "")
{ alert("No file selected");
//return;
}
else
{
$.ajax({
beforeSend: function(){
{ $("#frmFileUpload").ajaxSubmit();
$.blockUI();
}
},
success: function(result)
{ alert(result);
$.unblockUI();
}
});
答案 0 :(得分:0)
响应实际上在responseText字段中,因此您的代码应该是
alert(result.responseText);