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


Java HttpSession.isNew方法代碼示例

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


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

示例1: login

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
@PostMapping(value = "/login")
public ResponseEntity<?> login(String phone, String password, HttpSession session) {

    User user = userService.login(phone, password);

    if (session.isNew()) {
        logger.info("Successfully creates a session ,the id of session :" + session.getId());
    } else {
        logger.info("session already exists in the server, the id of session :"+ session.getId());
    }

    if (user != null) {
        session.setAttribute("userId", user.getId());
        return new ResponseEntity<>(new UserInShort(user.getUsername(), user.getGender(), user.getPhone()), HttpStatus.OK);
    }
    else
        throw new UnauthorizedException("用戶名或密碼錯誤");


}
 
開發者ID:SkyeBeFreeman,項目名稱:ticket-booking-back-end,代碼行數:21,代碼來源:UserController.java

示例2: getServletResponse

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
 * Returns the final response from the servlet. Note that this method should
 * only be invoked after all processing has been done to the servlet response.
 **/
public WebResponse getServletResponse() throws IOException {
    if (_contextStack.size() != 1) throw new IllegalStateException( "Have not returned from all request dispatchers" );
    if (_webResponse == null) {
        HttpSession session = getRequest().getSession( /* create */ false );
        if (session != null && session.isNew()) {
            Cookie cookie = new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, session.getId() );
            cookie.setPath( _application.getContextPath() );
            getResponse().addCookie( cookie );
        }
        _webResponse = new ServletUnitWebResponse( _client, _frame, _effectiveURL, getResponse(), _client.getExceptionsThrownOnErrorStatus() );
    }
    return _webResponse;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:InvocationContextImpl.java

示例3: removeUserSession

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
 * 移除用戶Session
 */
public synchronized static void removeUserSession(Long userId) {
    Map<Long, String> userSessionMap = getSessionIds();
    if (userSessionMap.containsKey(userId)) {
        String sessionId = userSessionMap.get(userId);
        HttpSession httpSession = singleLoginSessionMap.get(sessionId);
        if (!httpSession.isNew()) {
            httpSession.removeAttribute(OpencronTools.LOGIN_USER);
            //httpSession.invalidate();
        }
        singleLoginSessionMap.remove(sessionId);
    }
}
 
開發者ID:wolfboys,項目名稱:opencron,代碼行數:16,代碼來源:SingleLoginListener.java

示例4: sessionCookieSource

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
private SessionConfig.SessionCookieSource sessionCookieSource() {
    HttpSession session = getSession(false);
    if(session == null || session.isNew()) {
        return SessionConfig.SessionCookieSource.NONE;
    }
    if(sessionCookieSource == null) {
        sessionCookieSource = originalServletContext.getSessionConfig().sessionCookieSource(exchange);
    }
    return sessionCookieSource;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:HttpServletRequestImpl.java

示例5: isEncodeable

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
 * Return <code>true</code> if the specified URL should be encoded with
 * a session identifier.  This will be true if all of the following
 * conditions are met:
 * <ul>
 * <li>The request we are responding to asked for a valid session
 * <li>The requested session ID was not received via a cookie
 * <li>The specified URL points back to somewhere within the web
 * application that is responding to this request
 * </ul>
 *
 * @param location Absolute URL to be validated
 */
private boolean isEncodeable(final String location) {

    if (location == null)
        return (false);

    // Is this an intra-document reference?
    if (location.startsWith("#"))
        return (false);

    // Are we in a valid session that is not using cookies?
    final HttpServletRequestImpl hreq = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getOriginalRequest();

    // Is URL encoding permitted
    if (!originalServletContext.getEffectiveSessionTrackingModes().contains(SessionTrackingMode.URL)) {
        return false;
    }

    final HttpSession session = hreq.getSession(false);
    if (session == null) {
        return false;
    } else if (!hreq.isRequestedSessionIdFromURL() && !session.isNew()) {
        return false;
    }

    return doIsEncodeable(hreq, session, location);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:40,代碼來源:HttpServletResponseImpl.java

示例6: getServletResponse

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
 * Returns the final response from the servlet. Note that this method should
 * only be invoked after all processing has been done to the servlet response.
 **/
public WebResponse getServletResponse() throws IOException {
    if (_webResponse == null) {
        HttpSession session = _request.getSession( /* create */ false );
        if (session != null && session.isNew()) {
            Cookie cookie = new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, session.getId() );
            cookie.setPath( _application.getContextPath() );
            _response.addCookie( cookie );
        }
        _webResponse = new ServletUnitWebResponse( _client, _target, _requestURL, _response, _client.getExceptionsThrownOnErrorStatus() );
    }
    return _webResponse;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:17,代碼來源:InvocationContextImpl.java

示例7: doPost

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	HttpSession session;
	session = request.getSession();
	if (session.isNew()) {
		redirectToLogin(request, response);
	} else {
		Patient patient = new DatabaseHelper().getPatient((int) session.getAttribute("UserID"));
		Appointment appointment = new Appointment(patient, (String) request.getParameter("symptons"),
				(String) request.getParameter("disease"),
				DateUtils.getLongFromDate((String) request.getParameter("preferredDate")),
				(String)request.getParameter("title"));


		// insert in DB
		int status = new DatabaseHelper().createAppointment(appointment);
		if (status > 0) {
			// successfully inserted
			// redirect to patient dashboard
			RequestDispatcher rs;
			rs = request.getRequestDispatcher("patient");
			request.setAttribute("personId", appointment.getPatient().getId());
			rs.forward(request, response);
		} else {
			// error 
			//redirect to login
			redirectToLogin(request, response);
		}
	}
}
 
開發者ID:jainkuniya,項目名稱:central-medic-center,代碼行數:36,代碼來源:BookAppointment.java


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