如何在 ReSTLet(Google 应用引擎 2.0 版)中设置内容类型?在本例中,我想将内容类型设置为“”text/xml”。
我有:
public class SubResource extends ServerResource {
@Get
public Representation get(Representation representation){
setStatus(Status.SUCCESS_OK);
StringRepresentation sr = new StringRepresentation(getSomeXml());
return sr;
}
}
我不确定即使它是在 Representation 中设置的值,或者它是否以与返回代码相同的方式从 ServerResource 类设置。
答案:
StringRepresentation sr = new StringRepresentation(getSomeXml());
sr.setMediaType(MediaType.TEXT_XML);
<小时/>
最佳答案
除非GAE风格中有什么我不知道的东西,否则我认为不需要那么复杂。这对我有用:
@Get( value = "xml" )
public String myMethodNameHere(){
return getSomeXml();
}
关于java - 设置内容/媒体类型 - ReSTLet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3027014/