本文整理汇总了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";
}
示例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());
}
}
示例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";
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}