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


Java ServletActionContext.getRequest方法代碼示例

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


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

示例1: intercept

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
@Override
public String intercept(final ActionInvocation invocation) throws Exception {

    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession(true);

    Locale locale = (Locale) session.getAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE);
    // Locale adminpagelocale = (Locale)
    // session.getAttribute(ADMIN_PAGE_LOCALE);
    // if (locale == null && adminpagelocale == null) {
    if (locale == null) {
        if (request.getLocale().equals(Locale.CHINA) || request.getLocale().equals(Locale.CHINESE)) {
            session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.CHINA);
            logger.debug("Language is set to Chinese. from IP <" + request.getRemoteAddr() + ">");
        } else if (request.getLocale().equals(Locale.JAPAN) || request.getLocale().equals(Locale.JAPANESE)) {
            session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.JAPAN);
            logger.debug("Language is set to Japanese. from IP <" + request.getRemoteAddr() + ">");
        } else {
            session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.US);
            logger.debug("Language is set to English.from IP <" + request.getRemoteAddr() + ">");
        }
    }
    // else if (adminpagelocale != null) {
    // session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE,
    // adminpagelocale);
    // }
    if (invocation.getAction() instanceof AbstractAdminBaseAction
            && (locale == null || !locale.equals(Locale.CHINA))) {
        // 使用中文界麵
        // session.setAttribute(ADMIN_PAGE_LOCALE,
        // session.getAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE));
        session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.CHINA);
        logger.debug("because access page is admin page. Language is set to Chinese. from IP <"
                + request.getRemoteAddr() + ">");
    }
    return invocation.invoke();
}
 
開發者ID:luckyyeah,項目名稱:YiDu-Novel,代碼行數:38,代碼來源:SetLanguageInterceptor.java

示例2: login

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
/**
 * Performs a login using JAAS / Container authentication. Further the method populates the session
 * attribute SUBJECT with a JAAS subject for the user. The subject is either populated from the container
 * such as jetty or an additional JAAS login is performed to obtain the subject.
 * @return
 *  SUCCESS if the login was successful, otherwise ERROR is returned.
 * @throws Exception
 */
public String login() throws Exception {

    if (isInvalid(getUsername())) {
        return INPUT;
    }
    if (isInvalid(getPassword())) {
        return INPUT;
    }

    final HttpServletRequest request = ServletActionContext.getRequest();
    final HttpSession session = request.getSession();

    //perform container login
    try {
        request.login(username, password);
    } catch(ServletException e){
        LOG.error("Login failed", e);
        return Action.ERROR;
    }

    //try to obtain the Subject from the container or perform an _additional_ login
    //in order to get the subject.
    final Optional<Subject> subject = Stream.of(jettySupport,
                                                new LoginModuleAuthSupport(getUsername(), getPassword()))
                                            .map(f -> f.apply(session))
                                            .findFirst()
                                            .flatMap(identity());

    //register the subject in the session so we can obtain it without vendor specific
    //access logic (such as Jetty's)
    //see RunAsInterceptor where we need this
    subject.ifPresent(subj -> session.setAttribute("SUBJECT", subj));
    return subject.map(s -> Action.SUCCESS).orElse(Action.ERROR);
}
 
開發者ID:gmuecke,項目名稱:boutique-de-jus,代碼行數:43,代碼來源:AuthAction.java

示例3: logout

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
/**
 * Logs out the user and invalidates the session
 * @return
 *  the method always returns SUCCESS or throws an error if logout fails.
 * @throws ServletException
 */
public String logout() throws ServletException {
    final HttpServletRequest request = ServletActionContext.getRequest();
    final HttpSession session = request.getSession();

    //perform container login
    request.logout();
    session.invalidate();
    return SUCCESS;
}
 
開發者ID:gmuecke,項目名稱:boutique-de-jus,代碼行數:16,代碼來源:AuthAction.java

示例4: getAllReaderType

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
public String getAllReaderType(){

	List<ReaderType> allReaderType = readerTypeService.getAllReaderType();
	HttpServletRequest request = ServletActionContext.getRequest();
	request.setAttribute("readerTypes", allReaderType);
	return "success";
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:8,代碼來源:ReaderTypeManageAction.java

示例5: getRequest

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
/**
 * 得到request
 * 
 * @return
 */
public static HttpServletRequest getRequest() {
	HttpServletRequest request = ServletActionContext.getRequest();
	System.out.println("request=>"+request);
	return request;
}
 
開發者ID:liuxuanhai,項目名稱:WeiXing_xmu-2016-MrCode,代碼行數:11,代碼來源:WebApplication.java

示例6: execute

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
@Override
public String execute() {

    HttpServletRequest request = ServletActionContext.getRequest();
    try {
        AccessToken accessTokenObj = new Oauth().getAccessTokenByRequest(request);
        String accessToken = null;
        String openID = null;
        if (StringUtils.isEmpty(accessTokenObj.getAccessToken())) {
            logger.warn("沒有獲取到響應參數");
        } else {
            accessToken = accessTokenObj.getAccessToken();
            OpenID openIDObj = new OpenID(accessToken);
            openID = openIDObj.getUserOpenID();
            com.qq.connect.api.qzone.UserInfo qzoneUserInfo = new com.qq.connect.api.qzone.UserInfo(accessToken,
                    openID);
            com.qq.connect.javabeans.qzone.UserInfoBean userInfoBean = qzoneUserInfo.getUserInfo();
            if (userInfoBean.getRet() == 0) {
                TUser user = null;
                if (LoginManager.isLoginFlag()) {
                    // 登錄狀態綁定
                    user = LoginManager.getLoginUser();
                    user.setOpenid(openID);
                    user.setModifytime(new Date());
                    userService.save(user);
                } else {
                    // 未登錄狀態添加用戶
                    // 根據openid查詢用戶信息
                    user = userService.findByOpenid(openID);

                    if (user == null) {
                        // 用戶不存在的話,新建用戶
                        user = new TUser();
                        user.setLoginid(userInfoBean.getNickname());
                        // 設置默認隨機密碼
                        user.setPassword(Utils.convert2MD5(userInfoBean.getNickname() + Utils.getRandomString(32)));
                        user.setSex(StringUtils.equals(userInfoBean.getGender(), "男") ? (short) 1 : (short) 2);
                        user.setType(YiDuConstants.UserType.NORMAL_USER);
                        user.setRegdate(new Date());
                        user.setDeleteflag(false);
                        user.setActivedflag(true);
                        user.setOpenid(openID);
                        user.setModifytime(new Date());
                    }
                    user.setLastlogin(new Date());
                    userService.save(user);
                }
                LoginManager.doLogin(user);
                // 保存用的登錄信息
                Cookie cookie = CookieUtils.addUserCookie(user);
                // 添加cookie到response中
                ServletActionContext.getResponse().addCookie(cookie);
            } else {
                logger.warn("很抱歉,我們沒能正確獲取到您的信息,原因是: " + userInfoBean.getMsg());
            }
        }

    } catch (QQConnectException e) {
        logger.warn("連接失敗:" + e.getMessage());
    }

    return REDIRECT;
}
 
開發者ID:Chihpin,項目名稱:Yidu,代碼行數:64,代碼來源:QQLoginAction.java

示例7: getRequest

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
/**
 * 取得HttpRequest的簡化函數.
 */
public static HttpServletRequest getRequest() {
    return ServletActionContext.getRequest();
}
 
開發者ID:dragon-yuan,項目名稱:Ins_fb_pictureSpider_WEB,代碼行數:7,代碼來源:BaseUtils.java

示例8: getRequest

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
/**
 * 獲取request
 * @return 
 */
public static HttpServletRequest getRequest()
{
	return ServletActionContext.getRequest();
}
 
開發者ID:cendi2005,項目名稱:jshERP,代碼行數:9,代碼來源:BaseAction.java

示例9: listByPage

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
/**
 * 分頁查詢
 * @return
 */
public String listByPage() {

    HttpServletRequest request = ServletActionContext.getRequest();  //取得請求對象
    String strPageNum = request.getParameter("pageNum");
    //String strPageSize = request.getParameter("pageSize");

    GrabSatinDao grabSatinDao = new GrabSatinImpl();

    if (strPageNum != null && !"".equals(strPageNum) ) {
        int pageNum = Integer.parseInt(strPageNum);
       // int pageSize = Integer.parseInt(strPageSize);

        satinList = grabSatinDao.getSatinData(10, pageNum);

    }

    return "pageSatin";
}
 
開發者ID:monsterLin,項目名稱:ReadMe,代碼行數:23,代碼來源:IndexAction.java

示例10: validateLogin

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
/**
 * 管理員登陸驗證
 * @return	返回 Struts2 配置字符串,引導頁麵跳轉
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public String validateLogin() throws Exception {
	
	int curPage = 1;
	Pager pager8 = null;
	List<NewsInfo> newsInfos8 = null;
	HttpServletRequest req = ServletActionContext.getRequest();
	DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
	// 驗證數據庫是否存在改管理員
	Admin admin = new Admin(loginName, loginPwd);
	List<Admin> list = (List<Admin>) adminBiz.login(admin);
	// 判斷管理員權限
	if (list.size() > 0) {
		// 取得權限
		if (pager != null) {
			curPage = pager.getCurPage();
		}
		if (newsInfo == null) {
			// 指定查詢條件為空
			pager = newsInfoBiz.getPagerOfAllNewsInfo(8);
			newsInfos8 = (List<NewsInfo>) newsInfoBiz.getAllNewsInfoByPage(curPage, 8);
		} else {
			// 存在指定查詢條件
			pager = newsInfoBiz.getPagerOfNewsInfo(newsInfo, 8);
			newsInfos8 = (List<NewsInfo>) newsInfoBiz.getNewsInfoByConditionAndPage(newsInfo, curPage, 8);
		}
		pager8 = pager;
		pager8.setCurPage(curPage);
		pager8.setTotalPage(pager8.getTotalPage());
		System.out.println("調試:--> "+pager8.toString());
		// 將數據存入請求以供前台獲取
		session.put("topicList", topicBiz.getAllTopics());
		session.put("newsInfoList8", newsInfos8);
		session.put("pager8", pager8);
		// CMS 首頁顯示登錄信息
		request.put("loaded", "success");
		session.put("admin", list.get(0));
		session.put("ip", adminUtil.getIpAddr(req));
		session.put("time", df.format(new Date()));
		return "index";
	} else {
		// 未取得管理員權限,駁回,輸出提示
		request.put("notice", "Account/Password is mismatched");
		return "login";
	}
}
 
開發者ID:RyougiChan,項目名稱:NewsSystem,代碼行數:52,代碼來源:AdminAction.java

示例11: getRequest

import org.apache.struts2.ServletActionContext; //導入方法依賴的package包/類
/**
 * 取得HttpRequest的簡化函數.
 */
public static HttpServletRequest getRequest() {
	return ServletActionContext.getRequest();
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:7,代碼來源:Struts2Utils.java


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