Alfresco - HTTP Sessions

ぃ、小莉子 提交于 2019-12-11 09:57:27

问题


Trying to access the HTTP session through Javascript Webscripts on QuickStart.

I am unable to find any help in saving elements to some private object for each http session.

Does anyone know of any solutions?


回答1:


  1. Create a custom JavaScript root object - it is a Java class which implements org.springframework.extensions.webscripts.processor.BaseProcessorExtension class, for example:

    package pl.test;
    
    import javax.servlet.http.HttpSession;
    
    import org.springframework.extensions.surf.ServletUtil;
    import org.springframework.extensions.webscripts.processor.BaseProcessorExtension;
    
    public class HttpSessionHelper extends BaseProcessorExtension {
    
    public void setInSession(String paramName, String paramValue) {
        HttpSession session = ServletUtil.getSession();
        session.setAttribute(paramName, paramValue);
    }
    
    public String getFromSession(String paramName) {
        HttpSession session = ServletUtil.getSession();
    
        Object paramValue = session.getAttribute(paramName);
        if (paramValue != null) {
            return paramValue.toString();
        } else {
            return null;
        }
    }
    }
    
  2. Compile and package this class to jar archive and copy it to Share (or Surf based application).

  3. Register this class in spring-surf-script-services-context.xml, for example:

    <bean id="exampleExtension" parent="baseScriptExtension" 
          class="pl.test.HttpSessionHelper">
      <property name="extensionName">
         <value>httpSessionHelper</value>
      </property>
    </bean>
    
  4. Use your new custom root object in webscript, for example:

    var paramName = httpSessionHelper.getFromSession('paramName');
    httpSessionHelper.setInSession('paramName','paramValue');
    


来源:https://stackoverflow.com/questions/10304326/alfresco-http-sessions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!