当前位置: 首页>>代码示例>>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;未经允许,请勿转载。