我的问题:json 字符串作为文件返回。当我调用 getJSONResult 操作时,它会给我一个包含 json 字符串的文件,我可以打开或下载该文件。
我认为这是配置问题,但我找不到。如果有人能帮助我,我会很高兴,谢谢大家!
我有一个带有提交的打开表单,该表单使用操作和执行方法来获取数据。然后,我能让 jquery 工作的唯一方法是放置一个仅返回“成功”的操作和执行方法,然后我使用第三个操作进入我的 jquery 网格。
struts.xml
<struts>
<package name="live" namespace="/live" extends="struts-default,json-default">
<action name="gridAction" class="core.action.AdminAction">
<result name="success" type="json"></result>
<result name="error">/live/YYY.jsp</result>
</action>
</package>
</struts>
最佳答案
我假设你使用的是 Internet Explorer,因为我从来没有遇到过 Google Chrome 的这个问题(甚至有一个插件可以很好地格式化它:https://chrome.google.com/webstore/detail/chklaanhfefbnpoihckbnefhakgolnmc)
四处搜索,我想出了两个页面,它们为您的问题提供了相同的解决方案,如果您确实在使用 IE:
View JSON in Internet Explorer
How can I convince IE to simply display application/json rather than offer to download it?
解决方案的要点在于:
需要在 IE 中查看 JSON 响应?
打开记事本并粘贴以下内容:
Windows Registry Editor Version 5.00; ; Tell IE 7,8,9 to open JSON documents in the browser on Windows XP and later. ; 25336920-03F9-11cf-8FD0-00AA00686F13 is the CLSID for the "Browse in place" . ; [HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/json] "CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}" "Encoding"=hex:08,00,00,00 [HKEY_CLASSES_ROOT\MIME\Database\Content Type\text/json] "CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}" "Encoding"=hex:08,00,00,00
- 将文档保存为 IE-Json.reg 然后运行它。 注意:这已经在 Windows XP 和 Windows 7 上使用 IE 7、8、9 进行了测试。
关于java - 获取 JSON 弹出窗口以保存或打开对话框而不是实际内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11625389/