Springmc uses .jpg as the suffix to access request problem analysis

For requesting access using jpg as the suffix name, there may be a problem that the session cannot save data. For example: @RequestMapping(value = "/captcha.jpg") can come to the browser to get the captcha image through http://localhost:8080/captcha.jpg, request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText) ;

Used to save the verification code text, but other requests cannot use request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);

When the value in the session is obtained, null always appears. After searching the data, it is found that the link is only used as an external link to display the picture, and the external cannot obtain the request information through the session. It can be understood that requests ending with .jpg will be regarded as static resource access and cannot generate a session.



It is hereby noted that the problems that arise during the test are hereby noted. Corrections are made when the best explanation is found.

The real reason is that the CacheSessionDAO that inherits EnterpriseCacheSessionDAO is set

 @Override
    protected void doUpdate(Session session) 

// If it is a static file, do not update SESSION
if (Servlets.isStaticFile(uri)){
return;
}

super.doUpdate(session);

@Override
    protected Serializable doCreate(Session session)

// If it is a static file, do not create a SESSION
if (Servlets.isStaticFile(uri)){
       return null;
}

@Override
    public Session readSession(Serializable sessionId)

// If it is a static file, do not get SESSION
    if (Servlets.isStaticFile(uri)){
    return null;
    }


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326430351&siteId=291194637