javascript - 百度ueditor上传图片,其路径前台与后台得到的值不一致?

查看:349
本文介绍了javascript - 百度ueditor上传图片,其路径前台与后台得到的值不一致?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

用的是ueditor自带的图片上传功能,上传完成后前台能得到完整的img标签,于是通过ue.getContent();得到编辑器的html内容.
这时的img标签是完整的,带有src的如图

结果后台我接受这个内容变量发现它居然变成了这样


找了很久都不知道错在哪里啊...
这是页面ajax提交的代码
function saveInfo(parm){

        var ue=UE.getEditor('infoContent');
        var infoContentHtml='';
        ue.ready(function(){
            infoContentHtml=ue.getContent();
        })
        alert(infoContentHtml);
        var url="${ctx}/wznrfb/saveOrUpdateInfo?publishState=0&infoType="+${infoType}+"&infoContentHtml="+infoContentHtml;
        if(parm=="2"){
            url="${ctx}/wznrfb/saveOrUpdateInfo?publishState=1&infoType="+${infoType}+"&infoContentHtml="+infoContentHtml;
        }
        var content = UE.getEditor('infoContent').getContent();
        //判断标题是否为空
        if($('#infoTitle').val()==""){
            ui.alert("标题不能为空");
            return false;
        }
        //判断内容是否为空
        if (!UE.getEditor('infoContent').hasContents()) {
            ui.alert("内容不能为空!");
            //ui.alert('内容不能为空!', '3000');
            return false;
        }
        $('#f2').ajaxSubmit({
               url:url,
               type:'post',
               dataType:"json",
               error:function(data){
                   ui.alert("发生错误,请联系管理员!");
               },
               success:function(data){
                   closeWin1();
                   if(data==1){
                       ui.alert("保存成功!");  
                   }else{
                       ui.alert("保存失败!");  
                   }
                   
                   parent.btnQuery();
               }
               });
        return false;
    }

这是后台Controllor的接收方法
/**

 * 保存或更新新增信息
 * @param request
 * @param response
 * @throws ParseException 
 */
@RequestMapping(value="saveOrUpdateInfo",method=RequestMethod.POST)
public void saveOrUpdateInfo(HttpServletRequest request,HttpServletResponse response) throws ParseException{
    TD_XYPJ_PUBLIC_INFORMATION information;
    int count=0;
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String datestr=sdf.format(Calendar.getInstance().getTime());
    Long date=sdf.parse(datestr).getTime();
    String infoType=(StringUtils.isNotBlank(request.getParameter("infoType")))?request.getParameter("infoType"):request.getParameter("xxlx");
    String infoTitle=request.getParameter("infoTitle");
    String infoContentHtml=request.getParameter("infoContentHtml");
    String publishState=request.getParameter("publishState");
    String infoId=request.getParameter("infoId");
    if(StringUtils.isNotBlank(infoId)){//更新
        information=wznrfbService.findInfoById(infoId);
        information.setInfoType(infoType);
        information.setInfoTitle(infoTitle);
        information.setInfoContent(infoContentHtml);
        information.setPublishState(publishState);
        count=wznrfbService.updateInfo(information);
    }else{//新增
        information=new TD_XYPJ_PUBLIC_INFORMATION();
        information.setInfoId(UUID.randomUUID().toString());
        information.setOrgId(getOrgId());
        information.setUserId(getUserId());
        information.setInfoType(infoType);
        information.setInfoTitle(infoTitle);
        information.setInfoContent(infoContentHtml);
        information.setPublishState(publishState);
        information.setBrowseCounts("0");
        information.setPublishTime(new java.sql.Timestamp(date));
        count=wznrfbService.saveInfo(information);
    }
    try {
        this.writeWeb(response, String.valueOf(count));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

我的疑问就是为什么这两个值会不一样,我找不出是哪里会改动这个值的地方啊.
求大神解惑啊,我还只是个初级java开发员,代码写的不好请大神多多指点一下~~

解决方案

最终在组长的帮助下解决,问题的原因竟然是因为防注入的Xss过滤器中用''替换掉了类似于src=''这样的字符串...

晕,我怎么没想到过滤器上呢~~

这篇关于javascript - 百度ueditor上传图片,其路径前台与后台得到的值不一致?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆