当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletRequest.getSession方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getSession方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getSession方法的具体用法?Java HttpServletRequest.getSession怎么用?Java HttpServletRequest.getSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDescription

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public String getDescription(boolean includeClientInfo) {
	HttpServletRequest request = getRequest();
	StringBuilder sb = new StringBuilder();
	sb.append("uri=").append(request.getRequestURI());
	if (includeClientInfo) {
		String client = request.getRemoteAddr();
		if (StringUtils.hasLength(client)) {
			sb.append(";client=").append(client);
		}
		HttpSession session = request.getSession(false);
		if (session != null) {
			sb.append(";session=").append(session.getId());
		}
		String user = request.getRemoteUser();
		if (StringUtils.hasLength(user)) {
			sb.append(";user=").append(user);
		}
	}
	return sb.toString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:ServletWebRequest.java

示例2: getDelete

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@GetMapping("/delete/{id}")
public String getDelete(HttpServletRequest request, HttpServletResponse response, @PathVariable long id,
						Model model) throws IOException {
	HttpSession session = request.getSession(true);
	Entry entry = getEntryDao().getEntry(id);

	if(entry == null) {
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
		return null;
	}

	if(canEdit(session, entry)) {
		model.addAttribute("entry", entry);
		return "delete";
	}

	response.sendError(HttpServletResponse.SC_FORBIDDEN);
	return null;
}
 
开发者ID:kalsowerus,项目名称:Guestbook9001,代码行数:20,代码来源:EditController.java

示例3: doPost

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public void doPost(HttpServletRequest request, HttpServletResponse response)  
        throws ServletException, IOException {  
    
    String n=request.getParameter("username");  
    String p=request.getParameter("userpass"); 
    HttpSession session = request.getSession(false);
    
    DB dbProperties = new DB(getServletContext().getInitParameter("dbHost"), getServletContext().getInitParameter("dbPort"), getServletContext().getInitParameter("dbName"), getServletContext().getInitParameter("dbUser"), getServletContext().getInitParameter("dbPassword"));
    
    if(LoginDao.validate(n, p, request, dbProperties) != null){ 
        session.setAttribute("LoggedUser", LoginDao.validate(n, p, request, dbProperties));            
    } else{  
    	request.setAttribute("login_error", "<p style=\"color:red\">Sorry user name or password error</p>");
    }  

	RequestDispatcher rd = getServletContext().getRequestDispatcher(request.getContextPath() + "/login.jsp");
	rd.forward(request, response);
	
    doGet(request, response);
}
 
开发者ID:CanadianRepublican,项目名称:DDNS_Server,代码行数:21,代码来源:LoginServlet.java

示例4: doPost

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session = request.getSession();
    String name = request.getParameter("name") != null ? request.getParameter("name").trim() : "",
            viewLimit = request.getParameter("viewLimit") != null ? request.getParameter("viewLimit").trim() : "";

    if (name.isEmpty() || viewLimit.isEmpty()) {
        session.setAttribute("companyError", "Please enter a name and profile view limit");
    } else {
        Companies company = new Companies();
        company.setName(name);
        company.setViewLimit(Integer.parseInt(viewLimit));
        company.setProfilesViewed(0);
        company.setProfilesViewedThisMonth(0);

        try {
            company = CompanyDataAccessObject.persist(company);
            List<Companies> companyList = CompanyDataAccessObject.getAll();
            session.setAttribute("companyList", companyList);
        } catch (Exception e) {
            session.setAttribute("companyError", "An error occurred");
            e.printStackTrace();
        }
    }
    response.sendRedirect("admin/admin-company-list.jsp");
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:26,代码来源:AdministratorCreateCompanyServlet.java

示例5: handleGenericException

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@ExceptionHandler({Exception.class})
public ModelAndView handleGenericException(Exception ex, HttpServletRequest request) {
    //LOG HERE
    ModelAndView model = new ModelAndView("error");
    AppErrorInfo errorInfo = new AppErrorInfo();
    HttpSession session = request.getSession(false);

    errorInfo.setErrorCode("TIMESHEET.SERVER.ERROR");
    errorInfo.setErrorDetails("");
    errorInfo.setErrorMessage(messageSource.getMessage("internal.server.error",
            new String[]{}, Locale.US));
    errorInfo.setHttpStatusCode(500);
    errorInfo.setSessionId(session.getId());

    StringWriter sw = new StringWriter();
    ex.printStackTrace(new PrintWriter(sw));
    String s = sw.toString();
    errorInfo.setStackTrace(s);
    errorInfo.setTimeStamp(System.currentTimeMillis());

    model.addObject("ecasErrorInfo", errorInfo);
    return model;
}
 
开发者ID:Mahidharmullapudi,项目名称:timesheet-upload,代码行数:24,代码来源:GlobalExceptionHandler.java

示例6: authUser

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value="auth")
public void authUser(HttpServletRequest request,HttpServletResponse response,String email,String password) throws Exception{
	User usercent=new User();
	usercent.setEmail(email);
	usercent.setPassword(MD5Utils.MD5(password));
	User user=manageServiceImpl.valUserCenter(usercent);
       
	if (null != user) {
		LOG.info("login suc.");
		user.setLoginTimes(user.getLoginTimes()+1);
		user.setLastLoginIp(request.getRemoteAddr());
		manageServiceImpl.reCordUserLogin(user);
		HttpSession session = request.getSession();
		session.setAttribute("curUser", user);
		session.setAttribute("username", user.getUsername());
		
		setCookie(response, "name", user.getUsername(),"/", COOKIE_TIME);
		setCookie(response, "email", user.getEmail() + "","/", COOKIE_TIME);
		response.getWriter().print("suc");
	}else{
		response.getWriter().print("false");
	}
	
}
 
开发者ID:elves-project,项目名称:supervisor,代码行数:25,代码来源:HomeController.java

示例7: doSSOLogin

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static void doSSOLogin(HttpServletRequest httpRequest) {
    HttpSessionManager sessionManager =(HttpSessionManager) httpRequest.getAttribute(HttpSessionManager.class.getName());
    String alias = httpRequest.getParameter("_s");

    SessionRepository<Session> sessionRepository =
    (SessionRepository<Session>) httpRequest.getAttribute(SessionRepository.class.getName());
    for(Map.Entry<String, String> entry : sessionManager.getSessionIds(httpRequest).entrySet()) {
        String aliasId = entry.getKey();
        String sessionValue = entry.getValue();
        Session session = sessionRepository.getSession(sessionValue);
        HttpSession httpSession = httpRequest.getSession();
        if(session != null && session.getAttribute("username") != null && httpSession.getAttribute("username") == null ) {
            httpSession.setAttribute("username", session.getAttribute("username"));
        }

        log.info("[SSOLoginService] doSSOLogin aliasId {} : session value{}",aliasId,sessionValue);
    }

    if(StringUtils.isEmpty(alias)) {
        alias = sessionManager.getNewSessionAlias(httpRequest);
    }
    
    httpRequest.setAttribute("alias",alias);
}
 
开发者ID:xienjiang,项目名称:session-cloud,代码行数:25,代码来源:SSOLoginService.java

示例8: doUnlock

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 解锁客户端
 */
@RequestMapping("doUnlockCheck")
@ResponseBody
private AjaxResult doUnlock(HttpServletRequest request, @RequestParam("password") String password) {
    HttpSession session = request.getSession();
    UserEntity member = (UserEntity) session.getAttribute(IConstants.RBAC_SESSION_MEMBER);
    if (member.getPassword().equals(CommonUtils.MD5(password))) {
        session.setAttribute(IConstants.RBAC_SESSION_LOCK, null);
        return new AjaxResult();
    }
    return new AjaxResult(false, "密码错误!");
}
 
开发者ID:cx118118,项目名称:ssm-rbac,代码行数:15,代码来源:GlobalController.java

示例9: logout

import javax.servlet.http.HttpServletRequest; //导入方法依赖的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

示例10: getServiceResult

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    HttpSession session = request.getSession();

    CheStudio cheStudio = CallAction.getStudio(session);
    if (cheStudio != null) {
        SourcePickerViewWrap spv = cheStudio.getSourcePickerView();
        if (spv != null) {
            String xpath = request.getParameter("xpath").trim();
            spv.modifyXpathText(xpath);
        }
    }
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:14,代码来源:ModifyXPathText.java

示例11: service

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void service(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
    HttpSession session = req.getSession();
    session.invalidate();
    session = req.getSession();
    session.invalidate();
    req.getSession();
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:10,代码来源:TestBug49158.java

示例12: processRequest

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    HttpSession session = request.getSession();
    String modul = request.getParameter("modul");
    session.setAttribute("modul", modul);
    RequestDispatcher rd = request.getRequestDispatcher("JSP/ModulLevering.jsp");
        rd.include(request, response);    
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:19,代码来源:ModulLevering.java

示例13: doGet

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	HttpSession session = request.getSession();

	int clientID = Integer.parseInt(request.getParameter("clientID"));
	Clients client = ClientPersistence.getByID(clientID);

	session.setAttribute("client", client);
	response.sendRedirect("admin/admin-client-logs.jsp");
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:10,代码来源:AdministratorViewClientStatistics.java

示例14: doGet

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws IOException {
    HttpSession s = req.getSession(true);
    s.getId();
    res.getWriter().write("Hello world");
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:8,代码来源:TestTomcat.java

示例15: doLogout

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String doLogout(HttpServletRequest request) {

	HttpSession session = request.getSession();
	session.invalidate();

	return "index";
}
 
开发者ID:imaTowan,项目名称:Towan,代码行数:9,代码来源:TowanController.java


注:本文中的javax.servlet.http.HttpServletRequest.getSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。