国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Struts2返回XML,JSON格式
Java代碼 
 
Struts2返回XML格式
1.struts.xml里面的配置package extends="struts-default"
Java代碼 
 
<action name="actionName" class="bookTypeAction" method="methodName" >
<result name="xmlMessage" type="plaintext"></result>
</action>
2.Action里面的方法
Java代碼 
 
public void xxxMethod() throws IOException{
HttpServletResponse response = ServletActionContext.getResponse();
PrintWriter out = response.getWriter();
response.setContentType("application/xml;charset=UTF-8");
out.write("XML文檔");
}
Struts2返回Json格式
1.下載jsonplugin-0.7.jar包
如果用JSONObject把Object轉(zhuǎn)成JSON字符串的話需要下載下面的包
commons-beanutils-1.7.0.jar
json-lib-2.2.1-jdk15.jar
ezmorph-1.0.4.jar
2.Action里面的方法
Java代碼 
 
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);
//這是產(chǎn)生簡單的json的方法
response.getWriter().write("{success:"+isSuccess+",num:"+num+"}");
}else{
response.getWriter().write("{success:false,num:"+num+"}");
}
如果要把一個對象的實例轉(zhuǎn)成json,建議用JSONObject,
如:
Java代碼 
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
...
...
...
/**
* 通過bean生成JSON數(shù)據(jù)
* @param bean bean對象
* @return 生成的JSON數(shù)據(jù)
*/
public static String getJsonFromBean(Object bean){
try{
JSONObject JsonObject = JSONObject.fromObject(bean);
return JsonObject.toString();
}catch(Exception e){
e.printStackTrace();
}
return null;
}
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
JS中的JSON對象
android網(wǎng)絡(luò)編程
js與struts如何通過aja以json數(shù)據(jù)形式進行數(shù)據(jù)傳輸
jmeter壓測學(xué)習(xí)35-添加 BeanShell 斷言
JSONObject簡介
使用json-lib 數(shù)據(jù)格式轉(zhuǎn)換
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服