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


Java HttpServletRequest.getAttribute方法代碼示例

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


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

示例1: index

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping
   @PermessionLimit(superUser = true)
public String index(Model model, HttpServletRequest request) {

	// permission
	XxlApiUser loginUser = (request.getAttribute(LOGIN_IDENTITY_KEY)!=null)? (XxlApiUser) request.getAttribute(LOGIN_IDENTITY_KEY) :null;
	if (loginUser.getType()!=1) {
		throw new RuntimeException("權限攔截.");
	}

	List<XxlApiUser> userList = xxlApiUserDao.loadAll();
	if (CollectionUtils.isEmpty(userList)) {
		userList = new ArrayList<>();
	} else {
		for (XxlApiUser user: userList) {
			user.setPassword("***");
		}
	}
	model.addAttribute("userList", JacksonUtil.writeValueAsString(userList));

	return "user/user.list";
}
 
開發者ID:xuxueli,項目名稱:xxl-api,代碼行數:23,代碼來源:XxlApiUserController.java

示例2: postHandle

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
	Long long1 = (Long) request.getAttribute(EXECUTE_TIME_ATTRIBUTE_NAME);
	if (long1 == null) {
		Long long2 = (Long) request.getAttribute(START_TIME_ATTRIBUTE_NAME);
		Long long3 = Long.valueOf(System.currentTimeMillis());
		long1 = Long.valueOf(long3.longValue() - long2.longValue());
		request.setAttribute(START_TIME_ATTRIBUTE_NAME, long2);
	}
	if (modelAndView != null) {
		String s = modelAndView.getViewName();
		if (!StringUtils.startsWith(s, "redirect:"))
			modelAndView.addObject(EXECUTE_TIME_ATTRIBUTE_NAME, long1);
	}
	if (logger.isDebugEnabled()) {
		logger.debug((new StringBuilder("[")).append(handler).append("] executeTime: ").append(long1).append("ms").toString());
	}
}
 
開發者ID:wz12406,項目名稱:accumulate,代碼行數:19,代碼來源:ExecuteTimeInterceptor.java

示例3: login

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping("/login")
public String login(HttpServletRequest request) throws Exception{
	String exceptionClassName = (String) request.getAttribute("shiroLoginFailure");
	//根據shiro返回的異常類路徑判斷,拋出指定異常信息
	if(exceptionClassName!=null){
		if (UnknownAccountException.class.getName().equals(exceptionClassName)) {
			//最終會拋給異常處理器
			throw new UnknownAccountException("賬號不存在");
		} else if (IncorrectCredentialsException.class.getName().equals(
				exceptionClassName)) {
			throw new IncorrectCredentialsException("用戶名/密碼錯誤");
		}else {
			throw new Exception();//最終在異常處理器生成未知錯誤
		}
	}
	return "login";
}
 
開發者ID:fuyunwang,項目名稱:SSMShiro,代碼行數:18,代碼來源:IndexController.java

示例4: getActualLoginPage

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Get the relative URL for the login page. In case of a marketplace login
 * the path of the marketplace login page is returned. In case of a BES
 * login the passed default page is returned.
 * 
 * @param httpRequest
 *            - the HTTP request
 * @param defaultLoginPage
 *            - the path of page to be shown if it is no marketplace login.
 * 
 * @return see above.
 */
protected String getActualLoginPage(HttpServletRequest httpRequest,
        String defaultLoginPage, AuthenticationSettings authSettings) {

    if (BesServletRequestReader.isMarketplaceRequest(httpRequest)) {
        return BaseBean.MARKETPLACE_LOGIN_PAGE;
    }

    // Check if service login for a marketplace service is
    // requested. In this case add it as parameter to be treated by the
    // login panel.
    String loginType = (String) httpRequest
            .getAttribute(Constants.REQ_ATTR_SERVICE_LOGIN_TYPE);
    if (Constants.REQ_ATTR_LOGIN_TYPE_MPL.equals(loginType)) {
        String serviceLoginType = "?serviceLoginType=" + loginType;
        if (authSettings != null && authSettings.isServiceProvider()) {
            return BaseBean.SAML_SP_LOGIN_AUTOSUBMIT_PAGE
                    + serviceLoginType;
        } else {
            return BaseBean.MARKETPLACE_LOGIN_PAGE + serviceLoginType;
        }
    }

    return defaultLoginPage;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:37,代碼來源:BaseBesFilter.java

示例5: obtainHistoryNav

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/** This will search the request stream for the attribute 'historyNav'. If not found, it'll search for the parameter 'historyNav'.
 * This parameter is expected to be in XML format and will be decoded into a List
 * @param request The request stream.
 * @return The List containing the links for the HistoryNav.
 */
public static List obtainHistoryNav(HttpServletRequest request) {
    List historyNavList = null;

    // check to see if the List is present as an attribute in the request stream
    historyNavList = (List) request.getAttribute(HistoryNav.HISTORY_NAV_PARAMETER);
    if (historyNavList == null) {
        // now check to see if it was passed in as a parameter in the request stream
        String historyNavXml = request.getParameter(HistoryNav.HISTORY_NAV_PARAMETER);

        if (historyNavXml != null) {
            // the String will be in XML format.. so unmarshal it into a List
            historyNavList = decode(historyNavXml);
        }
    }

    return historyNavList;
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:23,代碼來源:HistoryNav.java

示例6: resolveTemplateResourceView

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Resolve Template Resource by View
 * @param request This is a HttpServletRequest
 * @param resource This is a resource to resolve for template
 * @param renderContext This is a RenderContext
 * @return view
 * @throws Exception
 */
public static View resolveTemplateResourceView(HttpServletRequest request, Resource resource, RenderContext renderContext)
        throws Exception {
    View view = null;
    Script script = (Script) request.getAttribute(JAHIA_SCRIPT);
    if (script != null){
        view = script.getView();
    } else {
        RenderService service = RenderService.getInstance();
        Resource pageResource = new Resource(resource.getNode(), HTML, null, Resource.CONFIGURATION_PAGE);
        Template template = service.resolveTemplate(pageResource, renderContext);
        pageResource.setTemplate(template.getView());

        JCRNodeWrapper templateNode = pageResource.getNode().getSession().getNodeByIdentifier(template.node);
        Resource wrapperResource = new Resource(templateNode, pageResource.getTemplateType(), template.view,
                Resource.CONFIGURATION_WRAPPER);
        script = service.resolveScript(wrapperResource, renderContext);
        if (script != null){
            view = script.getView();
        }
    }

    return view;
}
 
開發者ID:DantaFramework,項目名稱:JahiaDF,代碼行數:32,代碼來源:JahiaUtils.java

示例7: faqWxcard

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping("/insertfaq")
private @ResponseBody Map faqWxcard(HttpServletResponse resp,HttpServletRequest req) throws Exception{
	Map map = (Map) req.getAttribute("info");
	Userinfo user = (Userinfo) req.getAttribute("user");
	
	String openid = (String) map.get("openid");
	String email = (String) map.get("email");
	String description = (String) map.get("description");
	
	if(openid == null || "".equals(openid) || "null".equals(openid) || email == null || "".equals(email) || "null".equals(email) || description == null || "".equals(description) || "null".equals(description) ){
		throw new GlobalErrorInfoException(KeyvalueErrorInfoEnum.KEYVALUE_ERROR);
	}
	
	map.put("userid", user.getUserid());
	try{
		userinfoService.insertFaq(map);
	}catch(Exception e){
		throw new GlobalErrorInfoException(NodescribeErrorInfoEnum.NODESCRIBE_ERROR);
	}
	map.clear();
	map.put("code", "0");
	map.put("message", "operation success");
	return map;
}
 
開發者ID:viakiba,項目名稱:wxcard,代碼行數:25,代碼來源:UserApi.java

示例8: systemTime

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Return system time API
 *
 * @param request  HttpServletRequest
 * @param response HttpServletResponse
 * @throws Exception
 */
@RequestMapping("system_time")
@ResponseBody
public SystemTimeDto systemTime(HttpServletRequest request, HttpServletResponse response) throws Exception {

    final String clientId = (String) request.getAttribute(OAuth.OAUTH_CLIENT_ID);
    LOG.debug("Current clientId: {}", clientId);

    final String username = request.getUserPrincipal().getName();
    LOG.debug("Current username: {}", username);

    return new SystemTimeDto();
}
 
開發者ID:monkeyk,項目名稱:oauth2-shiro-redis,代碼行數:20,代碼來源:MobileResourcesController.java

示例9: getThrowable

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * 在request中獲取異常類
 * 
 * @param request
 * @return
 */
public static Throwable getThrowable(HttpServletRequest request) {
	Throwable ex = null;
	if (request.getAttribute("exception") != null) {
		ex = (Throwable) request.getAttribute("exception");
	} else if (request.getAttribute("javax.servlet.error.exception") != null) {
		ex = (Throwable) request.getAttribute("javax.servlet.error.exception");
	}
	return ex;
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:16,代碼來源:ExceptionUtil.java

示例10: getCurrentUser

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public static UserAuthDO getCurrentUser(HttpServletRequest request) {
    Object value = request.getAttribute("_userauth_attribute_key_");
    if (value == NULL) {
        return null;
    } else if (value == null) {
        String wxzid = getGidCookie(request);
        UserAuthDO userAuthDO = authenticate0(wxzid);
        request.setAttribute("_userauth_attribute_key_", userAuthDO == null ? NULL : userAuthDO);
        return userAuthDO;
    } else {
        return (UserAuthDO) value;
    }
}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:14,代碼來源:UserAuth.java

示例11: postHandle

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public void postHandle(HttpServletRequest request, //③
		HttpServletResponse response, Object handler,
		ModelAndView modelAndView) throws Exception {
	long startTime = (Long) request.getAttribute("startTime");
	request.removeAttribute("startTime");
	long endTime = System.currentTimeMillis();
	System.out.println("本次請求處理時間為:" + new Long(endTime - startTime)+"ms");
	request.setAttribute("handlingTime", endTime - startTime);
}
 
開發者ID:longjiazuo,項目名稱:springMvc4.x-project,代碼行數:11,代碼來源:DemoInterceptor.java

示例12: deleteArticle

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * 文章刪除
 * @Author : viakiba
 * @param req
 * @param resp
 * @return
 * @throws GlobalErrorInfoException
 * 2017-04-26
 */
@RequestMapping(value="/article/delete",method=RequestMethod.POST)
public ResultBody deleteArticle(HttpServletRequest req,HttpServletResponse resp) throws GlobalErrorInfoException{
	Map articlemap = (Map) req.getAttribute("jsoninfo");
	String article_id = (String) articlemap.get("article_id");
	if( article_id==null || "".equals("article_id") || "".equals(article_id)){
		throw new GlobalErrorInfoException(JsonKeyValueErrorInfoEnum.JSON_KEYVALUE_ERROR);
	}
	try {
		articlemap = articleServiceImpl.deleteArticle(articlemap);
	} catch (Exception e) {
		throw new GlobalErrorInfoException(NodescribeErrorInfoEnum.NO_DESCRIBE_ERROR);
	}
	return new ResultBody(new HashMap());
}
 
開發者ID:viakiba,項目名稱:karanotes,代碼行數:24,代碼來源:ArticleController.java

示例13: handleGeoLocationException

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@ExceptionHandler(GeoLocationException.class)
public ModelAndView handleGeoLocationException(HttpServletRequest request) {
    ModelAndView mav = new ModelAndView();
    String location = (String) request.getAttribute("location");
    String msg = webUI.getMessage(LOCATION_ERROR_MESSAGE_KEY, location);
    mav.addObject(LOCATION_ERROR_ATTRIBUTE, msg);
    mav.setViewName(PRODUCT_MAP_VIEW);
    return mav;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:10,代碼來源:GlobalController.java

示例14: extractClientCertificate

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Extract the client certificate from the specified HttpServletRequest or
 * null if none is specified.
 *
 * @param request http request
 * @return cert
 */
public X509Certificate[] extractClientCertificate(HttpServletRequest request) {
    X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");

    if (certs != null && certs.length > 0) {
        return certs;
    }

    if (logger.isDebugEnabled()) {
        logger.debug("No client certificate found in request.");
    }

    return null;
}
 
開發者ID:apache,項目名稱:nifi-registry,代碼行數:21,代碼來源:X509CertificateExtractor.java

示例15: HttpHeaderUser

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public HttpHeaderUser(final HttpServletRequest request) {
  final Claims claims = (Claims) request.getAttribute(CLAIM_ID);
  Preconditions.checkNotNull(claims);
  Preconditions.checkNotNull(claims.get(USER_ID));
  Preconditions.checkNotNull(claims.get(ROLES_ID));
  Preconditions.checkNotNull(claims.get(RULES_ID));

  final String userId = String.valueOf(claims.get(USER_ID));
  final String roles = StringUtils.join((List<String>) claims.get(ROLES_ID), ",");
  final String rules = StringUtils.join((List<String>) claims.get(RULES_ID), ",");
  this.userId = userId;
  this.roles = roles;
  this.rules = rules;
}
 
開發者ID:stefanstaniAIM,項目名稱:IPPR2016,代碼行數:15,代碼來源:HttpHeaderUser.java


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