當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletActionContext類代碼示例

本文整理匯總了Java中org.apache.struts2.ServletActionContext的典型用法代碼示例。如果您正苦於以下問題:Java ServletActionContext類的具體用法?Java ServletActionContext怎麽用?Java ServletActionContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServletActionContext類屬於org.apache.struts2包,在下文中一共展示了ServletActionContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getHistory

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * <p>
 * 取得閱讀曆史
 * </p>
 */
private void getHistory() {
    logger.debug("getHistory start.");
    // 獲得閱讀履曆
    String historys = CookieUtils.getHistoryCookie(ServletActionContext.getRequest());
    if (StringUtils.isNotEmpty(historys)) {
        String[] acnos = StringUtils.split(historys, ",");
        List<String> articlenoList = new ArrayList<String>();
        for (String articleAndchapterno : acnos) {
            String[] acnoArr = StringUtils.split(articleAndchapterno, "|");
            if (acnoArr.length > 0) {
                articlenoList.add(acnoArr[0]);
            }
        }
        if (articlenoList.size() > 0) {
            ArticleSearchBean searchBean = new ArticleSearchBean();
            searchBean.setArticlenos(StringUtils.join(articlenoList, ","));
            dto.setItems(articleService.find(searchBean));
        }
        dto.setCode(ReturnCode.SUCCESS);
    }
    logger.debug("getHistory normally end.");
}
 
開發者ID:luckyyeah,項目名稱:YiDu-Novel,代碼行數:28,代碼來源:AjaxServiceAction.java

示例2: findMyForfeitInfoByPage

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
public String findMyForfeitInfoByPage(){
	Reader reader = (Reader) ServletActionContext.getContext().getSession().get("reader");
	//獲取頁麵傳遞過來的當前頁碼數
	if(pageCode==0){
		pageCode = 1;
	}
	//給pageSize,每頁的記錄數賦值
	int pageSize = 5;
	PageBean<ForfeitInfo> pb = null;
	pb = forfeitService.findMyForfeitInfoByPage(reader,pageCode,pageSize);
	if(pb!=null){
		pb.setUrl("findMyForfeitInfoByPage.action?");
	}
	ServletActionContext.getRequest().setAttribute("pb", pb);
	return "success";
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:17,代碼來源:ForfeitAction.java

示例3: readerInfo

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 讀者個人資料
 * @return
 */
public String readerInfo(){
	Map<String, Object> session = ServletActionContext.getContext().getSession();
	Reader reader = (Reader) session.get("reader");
	reader.setName(name);
	reader.setPhone(phone);
	reader.setEmail(email);
	Reader newReader = readerService.updateReaderInfo(reader);
	int success = 0;
	if(newReader!=null){
		success = 1;
		//重新存入session
		session.put("reader", newReader);
	}
	try {
		ServletActionContext.getResponse().getWriter().print(success);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:26,代碼來源:ReaderInfoAction.java

示例4: deleteBookType

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 刪除圖書類型
 * @return
 */
public String deleteBookType(){
	BookType bookType = new BookType();
	bookType.setTypeId(id);
	boolean deleteType = bookTypeService.deleteBookType(bookType);
	int success = 0;
	if(deleteType){
		success = 1;
		//由於是轉發並且js頁麵刷新,所以無需重查
	}
	try {
		ServletActionContext.getResponse().getWriter().print(success);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		throw new RuntimeException(e.getMessage());
	}
	
	return null;
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:23,代碼來源:BookTypeManageAction.java

示例5: getLastChapterUrl

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 獲取最新章節URL
 * 
 * @return 最新章節URL
 */
public String getLastChapterUrl() {

    HttpServletResponse response = ServletActionContext.getResponse();
    String url = response.encodeURL(ReaderAction.URL + "?subdir=" + getSubdir() + "&articleno=" + getArticleno()
            + "&chapterno=" + getLastchapterno());

    if (YiDuConstants.yiduConf.getBoolean(YiDuConfig.ENABLE_PINYINURL, false)) {
        url = response.encodeURL(ReaderAction.URL + "?pinyin=" + getPinyin() + "&chapterno=" + getLastchapterno());
    }
    return url;
}
 
開發者ID:luckyyeah,項目名稱:YiDu-Novel,代碼行數:17,代碼來源:BookcaseDTO.java

示例6: getAllBookTypes

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 得到圖書類型的集合
 * ajax請求該方法
 * 返回圖書類型集合的json對象
 * @return
 */
public String getAllBookTypes(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	List<BookType> allBookTypes = bookTypeService.getAllBookTypes();
	
	
	
	String json = JSONArray.fromObject(allBookTypes).toString();//List------->JSONArray
	try {
		response.getWriter().print(json);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:22,代碼來源:BookAction.java

示例7: setReferer

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 設置Referer
 * 
 */
public static void setReferer() {
    String refererPath = (String) ServletActionContext.getRequest().getHeader(REFERER_KEY);
    // 如果URL裏沒有本站域名的話,設置本站域名為默認值
    if (!(StringUtils.contains(refererPath, YiDuConstants.yiduConf.getString(YiDuConfig.URI)) && StringUtils
            .contains(refererPath, YiDuConstants.yiduConf.getString(YiDuConfig.URI)))) {
        refererPath = YiDuConstants.yiduConf.getString(YiDuConfig.URI);
    }
    HttpSession session = getSession(true);
    logger.debug("REFERER_KEY : " + refererPath);
    session.setAttribute(REFERER_KEY, refererPath);
}
 
開發者ID:luckyyeah,項目名稱:YiDu-Novel,代碼行數:16,代碼來源:LoginManager.java

示例8: dologin

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * <p>
 * 用戶登錄
 * </p>
 */
private void dologin() {
    logger.info("dologin start.");
    TUser user = userService.findByLoginInfo(loginid, Utils.convert2MD5(password));
    if (user != null && user.getDeleteflag() != null && !user.getDeleteflag()) {
        // 正常登錄
        LoginManager.doLogin(user);
        // 更新用戶最後登錄時間
        user.setLastlogin(new Date());
        userService.save(user);
        Cookie cookie = CookieUtils.addUserCookie(user);
        // 添加cookie到response中
        ServletActionContext.getResponse().addCookie(cookie);
        dto.setCode(ReturnCode.SUCCESS);
        logger.debug("dologin normally end.");
    } else {
        dto.setCode(ReturnCode.FAILED);
        dto.setErr(getText("errors.login.failed"));
        logger.debug("dologin abnormally end.");
    }

}
 
開發者ID:luckyyeah,項目名稱:YiDu-Novel,代碼行數:27,代碼來源:AjaxServiceAction.java

示例9: readerPwd

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 讀者密碼修改
 * @return
 */
public String readerPwd(){
	Reader reader = (Reader) ServletActionContext.getContext().getSession().get("reader");
	int state = -1;//原密碼錯誤
	//取出原密碼進行比對
	if(reader.getPwd().equals(Md5Utils.md5(oldPwd))){
		if(newPwd.equals(confirmPwd)){
			state = 1;//修改成功
			reader.setPwd(Md5Utils.md5(newPwd));
			reader = readerService.updateReaderInfo(reader);
			//重新存入session
			ServletActionContext.getContext().getSession().put("reader", reader);
		}else{
			state = 0;//確認密碼不一致
		}
	}
	try {
		ServletActionContext.getResponse().getWriter().print(state);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:28,代碼來源:ReaderInfoAction.java

示例10: getBook

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 得到指定圖書編號的圖書信息
 * ajax請求該方法
 * 返回該圖書信息的json對象
 * @return
 */
public String getBook(){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=utf-8");
	Book book = new Book();
	book.setBookId(bookId);
	Book newBook = bookService.getBookById(book);//得到圖書
	
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	    public boolean apply(Object obj, String name, Object value) {
		if(obj instanceof Authorization||name.equals("authorization")){	
			return true;
		}else{
			return false;
		}
	   }
	});
	
	
	JSONObject jsonObject = JSONObject.fromObject(newBook,jsonConfig);
	try {
		response.getWriter().print(jsonObject);
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:34,代碼來源:BookManageAction.java

示例11: findReaderByPage

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 根據頁碼查詢讀者
 * @return
 */
public String findReaderByPage(){
	//獲取頁麵傳遞過來的當前頁碼數
	if(pageCode==0){
		pageCode = 1;
	}
	//給pageSize,每頁的記錄數賦值
	int pageSize = 5;
	PageBean<Reader> pb = readerService.findReaderByPage(pageCode,pageSize);
	if(pb!=null){
		pb.setUrl("findReaderByPage.action?");
	}
	//存入request域中
	ServletActionContext.getRequest().setAttribute("pb", pb);
	return  "success";
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:20,代碼來源:ReaderManageAction.java

示例12: addReaderType

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
public String addReaderType(){
	ReaderType readerType = new ReaderType();
	readerType.setReaderTypeName(readerTypeName);
	readerType.setPenalty(penalty);
	readerType.setMaxNum(maxNum);
	readerType.setBday(bday);
	readerType.setRenewDays(renewDays);
	boolean b = readerTypeService.addReaderType(readerType);
	int success = 0;
	if(b){
		success = 1;
	}
	try {
		ServletActionContext.getResponse().getWriter().print(success);//向瀏覽器響應是否成功的狀態碼
	} catch (IOException e) {
		// TODO Auto-generated catch block
		throw new RuntimeException(e.getMessage());
	}
	return null;
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:21,代碼來源:ReaderTypeManageAction.java

示例13: deleteReader

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 刪除指定管理員
 * @return
 */
public String deleteReader(){
	//刪除讀者需要注意的點:如果該讀者有尚未歸還的書籍或者尚未繳納的罰款,則不能刪除
	Reader reader = new Reader();
	reader.setReaderId(readerId);
	int success = readerService.deleteReader(reader);

	try {
		ServletActionContext.getResponse().getWriter().print(success);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		throw new RuntimeException(e.getMessage());
	}
	
	return null;
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:20,代碼來源:ReaderManageAction.java

示例14: getChapterListUrl

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
/**
 * 獲取章節列表URL
 * 
 * @return 分類列表URL
 */
public String getChapterListUrl() {
    HttpServletResponse response = ServletActionContext.getResponse();
    String url = response.encodeURL(ChapterListAction.URL + "?subdir=" + getSubdir() + "&articleno="
            + getArticleno());

    if (YiDuConstants.yiduConf.getBoolean(YiDuConfig.ENABLE_PINYINURL, false)) {
        url = response.encodeURL(ChapterListAction.URL + "?pinyin=" + getPinyin());
    }
    return url;
}
 
開發者ID:Chihpin,項目名稱:Yidu,代碼行數:16,代碼來源:TArticle.java

示例15: findBackInfoByPage

import org.apache.struts2.ServletActionContext; //導入依賴的package包/類
public String findBackInfoByPage(){
	
	//獲取頁麵傳遞過來的當前頁碼數
	if(pageCode==0){
		pageCode = 1;
	}
	//給pageSize,每頁的記錄數賦值
	int pageSize = 5;
	
	PageBean<BackInfo> pb = backService.findBackInfoByPage(pageCode,pageSize);
	if(pb!=null){
		pb.setUrl("findBackInfoByPage.action?");
	}
	//存入request域中
	ServletActionContext.getRequest().setAttribute("pb", pb);
	return  "success";
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:18,代碼來源:BorrowSearchAction.java


注:本文中的org.apache.struts2.ServletActionContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。