日期:2014-05-16 浏览次数:20429 次
<action name="actionName" class="bookTypeAction" method="methodName" >
<result name="xmlMessage" type="plaintext"></result>
</action>
public void xxxMethod() throws IOException{
HttpServletResponse response = ServletActionContext.getResponse();
PrintWriter out = response.getWriter();
response.setContentType("application/xml;charset=UTF-8");
out.write("XML文档");
}
HttpServletRequest request =ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
int bookTypeId = Integer.parseInt(request.getParameter("bookTypeId"));
int num = admimService.getDeleteBookTypeCond(bookTypeId);
response.setContentType(ContentType_JSON);
if(num == 0){
boolean isSuccess = true;
int x = admimService.deleteBookType(bookTypeId);
//这是产生简单的json的方法
response.getWriter().write("{success:"+isSuccess+",num:"+num+"}");
}else{
response.getWriter().write("{success:false,num:"+num+"}");
}
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
...
...
...
/**
* 通过bean生成JSON数据
* @param bean bean对象
* @return 生成的JSON数据
*/
public static String getJsonFromBean(Object bean){
try{
JSONObject JsonObject = JSONObject.fromObject(bean);
return JsonObject.toString();
}catch(Exception e){
e.printStackTrace();
}
return null;
}