惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
博客园 - 三生石上(FineUI控件)
S
Securelist
U
Unit 42
The Cloudflare Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Simon Willison's Weblog
Simon Willison's Weblog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog
T
Tenable Blog
The Hacker News
The Hacker News
The Register - Security
The Register - Security
IT之家
IT之家
博客园 - 【当耐特】
Spread Privacy
Spread Privacy
P
Privacy & Cybersecurity Law Blog
博客园_首页
T
Tailwind CSS Blog
人人都是产品经理
人人都是产品经理
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
T
Tor Project blog
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
V
Vulnerabilities – Threatpost
A
Arctic Wolf
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
V2EX
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Cyberwarzone
Cyberwarzone
V
Visual Studio Blog
月光博客
月光博客
爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
G
GRAHAM CLULEY
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Heimdal Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - 南郭先生kaka

待处理数据的两种模型 nginx重启无法找到PId的解决办法 Wiki版产品需求---产品需求文档到底是谁的?产品到底是谁的? 为什么说private方法是有罪的 XML2JSON 的【net.sf.json.JSONException: nu.xom.ParsingException must be followed by either attribute specifications, ">" or "/>"】问题解决办法 继承的第一原则 致那些不甘寂寞的人 使用XSLT转换XML2XML Java 模拟 Http Post WITH AS SQL语句的用法 【Code Style】多余判断 java.lang.NoClassDefFoundError错误 Spring 中Quartz配置数据库化 FactoryBean在XML中的依赖注入方法 Camel FTP中文目录解决办法 配置CentOS6.3 NFS Bean复制的几种框架性能比较(Apache BeanUtils、PropertyUtils,Spring BeanUtils,Cglib BeanCopier) 重读《目标》---目标 重读《目标》---序
上传File时,浏览器总是添加<pre>的解决办法
南郭先生kaka · 2013-06-03 · via 博客园 - 南郭先生kaka

       在使用Structs的FileUpload组件进行上传文件的时候,在返回的JSon字符串里面总是莫名其妙的添加了<pre>标签,例如返回内容为"{\"message\":\"导入文件已成功\",\"result\":\"OK\"}",在浏览器里面就变成了"<pre style="word-wrap: break-word; white-space: pre-wrap;">"{\"message\":\"导入文件已成功\",\"result\":\"OK\"}"</pre>",这样就导致Ajax解析返回值的时候出现错误。

         我的上传代码,默认总是进入到error的处理中。

 jQuery.ajaxFileUpload({
            type:"POST",
            url:"/****/upload.action?file="+fileName,
            secureuri:false,
            fileElementId:"upload",
            dataType: "json",
            success:function (data, status) {
                if (data != null) {
                    data = JSON.parse(data);
                    MBJ.alert("提示", data.message);
                } else {
                    MBJ.alert("提示", "上传文件出错, 服务器返回错误信息: status = " + status);
                }
            },
            error:function (data, status, e) {
                MBJ.alert("提示", "上传文件出错: status = " + status);
            }
        });

      谷歌了一圈之后,发现很多人和我是一样的,解决办法都是把response的返回类型设置为【text/html】。在Struts2中需要在Action的配置中这样设置。

<result name="success" type="json">
                <param name="root">msg</param>
                <param name="contentType">text/html;charset=UTF-8</param>
            </result>

     如果用的是annotation的方式的话,需要加上这句话

 @Action(value = "upload", results = { @Result(name = SUCCESS, params = { "root", "msg", "contentType",
            "text/html;charset=UTF-8" }, type = "json") })