本文整理汇总了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("用户名或密码错误");
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
}