umeditor在weblogic下上传失败的bug修复

2014-11-30 | By Jinyang | Filed in: 技术相关.

使用umeditor上传图片时,在tomcat下正常可行的代码在部署到weblogic后报:strict servlet API: cannot call getWriter() after getOutputStream() 的错误 。

修改:imageUp.jsp  如下:

<%@ page language=”java” contentType=”text/html; charset=utf-8″
pageEncoding=”utf-8″%>
<%@ page import=”com.baidu.ueditor.um.Uploader”%>
<%
//System.out.println(“imageUp page begin”);
request.setCharacterEncoding(“utf-8”);
response.setCharacterEncoding(“utf-8”);

String path = request.getContextPath();
String basePath = request.getScheme() + “://”
+ request.getServerName() + “:” + request.getServerPort()
+ path + “/”;
String url = “http://”
+ request.getServerName()
+ “:”
+ request.getServerPort()
+ request.getContextPath()
+ request.getServletPath().substring(0,
request.getServletPath().lastIndexOf(“/”) + 1);

Uploader up = new Uploader(request);
up.setSavePath(“upload”);
String[] fileType = { “.gif”, “.png”, “.jpg”, “.jpeg”, “.bmp” };
up.setAllowFiles(fileType);
up.setMaxSize(100000); //单位KB
up.upload();

String iSize = “100”;
if (null == up.getSize() || up.getSize().equalsIgnoreCase(“”)) {
} else {
iSize = up.getSize();
}

String callback = request.getParameter(“callback”);

String result = “{\”name\”:\”” + up.getFileName()
+ “\”, \”originalName\”: \”” + up.getOriginalName()
+ “\”, \”size\”: ” + iSize + “, \”state\”: \””
+ up.getState() + “\”, \”type\”: \”” + up.getType()
+ “\”, \”url\”: \”” + up.getUrl() + “\”}”;

result = result.replaceAll(“\\\\”, “\\\\”);
//System.out.println(“result:” + result);
if (callback == null) {

} else {
result = “<script>” + callback + “(” + result + “)</script>”;
}

%>
<%=result%>

 

以上的重点在于最后几句的修正:

去掉之前使用response.getWriter() 的使用,即可。

 


Tags:

发表评论

电子邮件地址不会被公开。 必填项已用*标注