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


Java HttpServletRequest.getRequestedSessionId方法代碼示例

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


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

示例1: doGet

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        useParameters(req);

        resp.getWriter().print("<!--" + req.getContentType() + "-->");
        resp.getWriter().print("<h1>Welcome to " + req.getServerName());

        String sqlQuery = "UPDATE sessions(last_visit) VALUES(now()) WHERE where sid = '" + req.getRequestedSessionId() + "')";
        resp.getWriter().print("<!--" + req.getQueryString() + "-->");

        String referrer = req.getHeader("Referer"); //Should have a higher priority
        if (referrer != null && referrer.startsWith("http://company.ca")) {
            req.getHeader("Host");
            req.getHeader("User-Agent");
            req.getHeader("X-Requested-With");
//            req.getHeader("X-Forwarded-For");
//            req.getHeader("X-ATT-DeviceId");
//            req.getHeader("X-Wap-Profile");
        }
    }
 
開發者ID:blackarbiter,項目名稱:Android_Code_Arbiter,代碼行數:21,代碼來源:BasicServlet.java

示例2: doGet

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setContentType("text/plain");
    PrintWriter pw = resp.getWriter();
    String sessionId = req.getRequestedSessionId();
    if (sessionId == null) {
        sessionId = "none";
    }
    pw.write(sessionId);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:12,代碼來源:TestCoyoteAdapter.java

示例3: addCookie

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 *  Add a session id cookie if appropriate. Can be overloaded to
 *  support a cluster.
 * @param conn
 * @param urlString
 * @param request
 * @since Struts 1.2.0
 */
protected void addCookie(URLConnection conn, String urlString, HttpServletRequest request) {
    if ((conn instanceof HttpURLConnection)
        && urlString.startsWith(request.getContextPath())
        && (request.getRequestedSessionId() != null)
        && request.isRequestedSessionIdFromCookie()) {
        StringBuffer sb = new StringBuffer("JSESSIONID=");
        sb.append(request.getRequestedSessionId());
        conn.setRequestProperty("Cookie", sb.toString());
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:IncludeTag.java

示例4: checkNotCsrfAttack

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Check that this request is not subject to a CSRF attack
 * @param request The original browser's request
 * @param sessionCookieName "JSESSIONID" unless it has been overridden
 */
private void checkNotCsrfAttack(HttpServletRequest request, String sessionCookieName)
{
    // A check to see that this isn't a csrf attack
    // http://en.wikipedia.org/wiki/Cross-site_request_forgery
    // http://www.tux.org/~peterw/csrf.txt
    if (request.isRequestedSessionIdValid() && request.isRequestedSessionIdFromCookie())
    {
        String headerSessionId = request.getRequestedSessionId();
        if (headerSessionId.length() > 0)
        {
            String bodySessionId = getHttpSessionId();

            // Normal case; if same session cookie is supplied by DWR and
            // in HTTP header then all is ok
            if (headerSessionId.equals(bodySessionId))
            {
                return;
            }

            // Weblogic adds creation time to the end of the incoming
            // session cookie string (even for request.getRequestedSessionId()).
            // Use the raw cookie instead
            Cookie[] cookies = request.getCookies();
            for (int i = 0; i < cookies.length; i++)
            {
                Cookie cookie = cookies[i];
                if (cookie.getName().equals(sessionCookieName) &&
                        cookie.getValue().equals(bodySessionId))
                {
                    return;
                }
            }

            // Otherwise error
            log.error("A request has been denied as a potential CSRF attack.");
            throw new SecurityException("Session Error");
        }
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:45,代碼來源:Batch.java

示例5: loginSite

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping(value = "login", method = RequestMethod.GET)
public String loginSite(HttpServletRequest request, HttpServletResponse response) {
    if (request.getRequestedSessionId() != null) {
        if (rememberMeService.autoLogin(request, response) != null)
            return "userAccount/userAccount";
    }
    return "loginAndRegistration/login";
}
 
開發者ID:xSzymo,項目名稱:Spring-web-shop-project,代碼行數:9,代碼來源:Login.java

示例6: start

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping(value = "", method = RequestMethod.GET)
public String start(HttpServletRequest request, HttpServletResponse response, Model model) {

    if (request.getRequestedSessionId() != null)
        rememberMeService.autoLogin(request, response);

    if (!(SecurityContextHolder.getContext().getAuthentication().getName().equals("anonymousUser")))
        model.addAttribute("logged", true);
    else
        model.addAttribute("logged", false);

    Iterable<Category> categories = categoriesService.findAll();
    model.addAttribute("categories", categories);
    return "shopStartPage";
}
 
開發者ID:xSzymo,項目名稱:Spring-web-shop-project,代碼行數:16,代碼來源:Shop.java

示例7: preHandle

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws Exception {
    //創建日誌實體
       LoggerEntity loggerEntity = new LoggerEntity();
       
       //獲取請求sessionId
       String sessionId = request.getRequestedSessionId();
       //設置sessionId
       loggerEntity.setSessionId(sessionId);
       
       //設置請求方法
       String method = request.getMethod();
       loggerEntity.setMethod(method);
       
       //設置訪問協議
       String protocol = request.getProtocol();
       loggerEntity.setProtocol(protocol);
       
       //請求路徑
       String url = request.getRequestURI();
       //設置請求地址
       loggerEntity.setUrl(url);
       
       //獲取請求參數信息
       String paramData = JSON.toJSONString(request.getParameterMap(),
               SerializerFeature.DisableCircularReferenceDetect,
               SerializerFeature.WriteMapNullValue);
       //設置請求參數內容json字符串
       loggerEntity.setParamData(paramData);
       
       //設置客戶端ip
       loggerEntity.setClientIp(LoggerUtils.getCliectIp(request));
       
       long requestTime = System.currentTimeMillis();
       loggerEntity.setTime(new Timestamp(requestTime));
       
       //設置請求開始時間
       request.setAttribute(LOGGER_SEND_TIME, requestTime);
       request.setAttribute(LOGGER_ENTITY, loggerEntity);
	return true;
}
 
開發者ID:SnailFastGo,項目名稱:springboot_op,代碼行數:43,代碼來源:LoggerInterceptor.java

示例8: invoke

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Select the appropriate child Context to process this request,
 * based on the specified request URI.  If no matching Context can
 * be found, return an appropriate HTTP error.
 *
 * @param request Request to be processed
 * @param response Response to be produced
 * @param valveContext Valve context used to forward to the next Valve
 *
 * @exception IOException if an input/output error occurred
 * @exception ServletException if a servlet error occurred
 */
public void invoke(Request request, Response response,
                   ValveContext valveContext)
    throws IOException, ServletException {

    // Validate the request and response object types
    if (!(request.getRequest() instanceof HttpServletRequest) ||
        !(response.getResponse() instanceof HttpServletResponse)) {
        return;     // NOTE - Not much else we can do generically
    }

    // Select the Context to be used for this Request
    StandardHost host = (StandardHost) getContainer();
    Context context = (Context) host.map(request, true);
    if (context == null) {
        ((HttpServletResponse) response.getResponse()).sendError
            (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
             sm.getString("standardHost.noContext"));
        return;
    }

    // Bind the context CL to the current thread
    Thread.currentThread().setContextClassLoader
        (context.getLoader().getClassLoader());

    // Update the session last access time for our session (if any)
    HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
    String sessionId = hreq.getRequestedSessionId();
    if (sessionId != null) {
        Manager manager = context.getManager();
        if (manager != null) {
            Session session = manager.findSession(sessionId);
            if ((session != null) && session.isValid())
                session.access();
        }
    }

    // Ask this Context to process this request
    context.invoke(request, response);

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:53,代碼來源:StandardHostValve.java


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