日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BaseAction

發布時間:2025/3/19 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BaseAction 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
struts的action需要繼承BaseAction 方便編寫action,記錄一下:

import?javax.servlet.http.HttpServletRequest;

import?javax.servlet.http.HttpServletResponse;

import?javax.servlet.http.HttpSession;


import?org.apache.struts2.ServletActionContext;


import?com.alibaba.fastjson.JSONObject;

import?com.opensymphony.xwork2.ActionContext;

import?com.opensymphony.xwork2.ActionSupport;

import?com.opensymphony.xwork2.util.ValueStack;


public?class?BaseAction?extends?ActionSupport?{



private?static?final?long?serialVersionUID?=?9007242859196909496L;

protected?static?final?String?FAILURE="failure";



/**

*?獲得ValueStack

*?@return

*/

public?ValueStack?getStack(){

return?ServletActionContext.getValueStack(getRequest());

}

/**

*?獲得request

*/

public?HttpServletRequest?getRequest()?{

return?ServletActionContext.getRequest();

}


/**

*?獲得response

*/

public?HttpServletResponse?getResponse()?{

return?ServletActionContext.getResponse();

}


/**

*?獲得session

*/

public?HttpSession?getSession()?{

return?getRequest().getSession();

}


/**

*?獲得servlet上下文

*/

public?ServletContext?getServletContext()?{

return?ServletActionContext.getServletContext();

}


/**

*?獲得action上下文

*/

public?ActionContext?getContext(){

return?ActionContext.getContext();

}


/**

*?向上下文中put值

*?@param?key

*?@param?value

*/

public?void?putContext(String?key,Object?value){

getContext().put(key,?value);

}


/**

*?獲得資源路徑

*/

public?String?getRealPath(String?path)?{

return?getServletContext().getRealPath(path);

}


/**

*?session?中存儲對象

*?@param?key

*?@param?value

*/

public?void?setAttribute(String?key,Object?value){

getSession().setAttribute(key,?value);

}


/**

*?獲得session中的對象

*?@param?param

*?@return

*/

public?Object?getAttribute(String?key){

return?getSession().getAttribute(key);

}


/**

*?獲得request里面的參數值

*?@param?arg0

*?@return

*/

public?String?getParameter(String?arg0){

return?getRequest().getParameter(arg0);

}


/**

*?獲得數組對象參數

*?@param?arg0

*?@return

*/

public?String[]?getParameterValues(String?arg0){

return?getRequest().getParameterValues(arg0);

}


/**

*?獲得int型參數

*?@param?arg0

*?@return

*/

public?int?getIntParameter(String?arg0){

String?p?=?getParameter(arg0);

try{

return?Integer.parseInt(p);

}catch(NumberFormatException?e){

return?-1;

}

}


public?long?getLongParameter(String?arg0){

String?p?=?getParameter(arg0);

try{

return?Long.parseLong(p);

}catch(NumberFormatException?e){

return?-1;

}

}


/**

*?獲得Boolean型參數

*?@param?args0

*?@return

*/

public?boolean?getBoolParameter(String?args0){

String?params?=?getParameter(args0);

if(?params!=null&&

("yes".equalsIgnoreCase(params)||

"1".equalsIgnoreCase(params)||

"true".equalsIgnoreCase(params)||

"do".equalsIgnoreCase(params)

)

){

return?true;

}

return?false;

}


public?String?execResult(JSONObject?json){

addActionMessage(json.getString("message"));

String?result?=?json.getString("result");

if(result==null?||?result.length()?==?0?){

return?SUCCESS;

}else{

return?result;

}

}


}

總結

以上是生活随笔為你收集整理的BaseAction的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。