REST 返回 xml
我有一个返回 JAXB 对象的 REST Web 服务。我已将 Mediatype 作为 JSON 提供给该方法。我正在使用 ajaxForm 插件将一些数据发送到此 WebService。
问题是,尽管在 Web 服务中将 JSON 作为媒体类型提供,并且在客户端 Javascript 中将其作为数据类型提供,但我仍然只得到 xmlDocument 作为返回的对象。
这是网络服务签名。我正在使用 Glassfish 3.1,所有功能都可以正确执行(在 server.log 中看到消息)。
@Path("GetJson")
public class GetJson
{
private static Logger logger = Logger.getLogger("GetJson");
@POST
@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
public Exceldatalist getJson(@Context HttpServletRequest request)
{
这是客户端代码。表单是:
<form id="form3" action="http://comp1:8080/RestWSGS/jersey/GetJson" style="display:none"
enctype="multipart/form-data" method="post">
<input id ="username" name="username" type="hidden" />
<input id ="purpose" name="purpose" type="hidden" value="new" />
<input id ="filename" name="filename" type="hidden" />
<input id ="password" name="password" type="hidden" value="abc"/>
<input id ="company" name="company" type="hidden" value="Third"/>
<input id ="ignoreSheet" name="ignoreSheet" type="hidden" />
<input type="submit" style="display:none" />
</form>
ajaxForm 调用是:
$('#form3').ajaxForm({
url: 'http://comp1:8080/RestWSGS/jersey/GetJson',
async: false,
type: 'POST',
cache: false,
dataType: 'json',
contentType: "multipart/form-data",
processData: false,
success: function(data)
{
myData = data;
alert('success '+myData);
}
});
除此之外,仅对表单调用 submit()
。
我不明白我做错了什么。我现在被困在这里有一段时间了...... 请帮我解决这个问题!
I have a REST Web service which returns a JAXB object. I have given a Mediatype as JSON to the method. I am using ajaxForm plugin to send some data to this WebService.
The problem is that inspite of giving JSON as mediatype in the webservice and also giving it in the client Javascript as the dataType, I am still getting only xmlDocument as the returned object.
This is the webservice signature. I am using Glassfish 3.1 and all the functionality gets executed properly (seen messages in the server.log).
@Path("GetJson")
public class GetJson
{
private static Logger logger = Logger.getLogger("GetJson");
@POST
@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
public Exceldatalist getJson(@Context HttpServletRequest request)
{
This is the client code. Form is :
<form id="form3" action="http://comp1:8080/RestWSGS/jersey/GetJson" style="display:none"
enctype="multipart/form-data" method="post">
<input id ="username" name="username" type="hidden" />
<input id ="purpose" name="purpose" type="hidden" value="new" />
<input id ="filename" name="filename" type="hidden" />
<input id ="password" name="password" type="hidden" value="abc"/>
<input id ="company" name="company" type="hidden" value="Third"/>
<input id ="ignoreSheet" name="ignoreSheet" type="hidden" />
<input type="submit" style="display:none" />
</form>
ajaxForm call is :
$('#form3').ajaxForm({
url: 'http://comp1:8080/RestWSGS/jersey/GetJson',
async: false,
type: 'POST',
cache: false,
dataType: 'json',
contentType: "multipart/form-data",
processData: false,
success: function(data)
{
myData = data;
alert('success '+myData);
}
});
Apart of this there is only a call for submit()
for the form.
I fail to understand what I am doing wrong. I am stuck here for some time now...
Please help me unravel this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我为解决这个问题所做的。
我从我的项目中删除了所有球衣和杰克逊罐子。
从 glassfish 安装目录/模块中删除了所有 jersey 和 jackson jar。从泽西岛取出所有最新的罐子并将它们放在那里。
然后从 glassfish 中删除 osgi-cache 并重新启动服务器。这解决了我的问题,但具体改变了什么我不能说!
This is what I did to resolve this.
I removed all jersey and jackson jars from my project.
deleted all jersey and jackson jars from glassfish installation directory/modules. Got all the latest jars from jersey and put them there.
Then deleted the osgi-cache from glassfish and restarted the server. This resolved my problem though what exactly changed I cannot say!!