Alfresco-HTTP会话 [英] Alfresco - HTTP Sessions

查看:61
本文介绍了Alfresco-HTTP会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过QuickStart上的Javascript Webscript访问HTTP会话。



我无法在将元素保存到每个http会话的某些私有对象中找到任何帮助。 / p>

有人知道任何解决方案吗?

解决方案


  1. 创建一个自定义JavaScript根对象-这是一个Java类,实现了 org.springframework.extensions.webscripts.processor.BaseProcessorExtension 类,例如:

      package pl.test; 

    import javax.servlet.http.HttpSession;

    import org.springframework.extensions.surf.ServletUtil;
    import org.springframework.extensions.webscripts.processor.BaseProcessorExtension;

    公共类HttpSessionHelper扩展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();

    对象paramValue = session.getAttribute(paramName);
    if(paramValue!= null){
    return paramValue.toString();
    } else {
    返回null;
    }
    }
    }


  2. 编译并打包此类进行jar存档并将其复制到Share(或基于Surf的应用程序)。


  3. 在spring-surf-script-services-context.xml中注册此类,例如:

     < bean id = exampleExtension parent = baseScriptExtension 
    class = pl。 test.HttpSessionHelper>
    <属性名称= extensionName>
    < value> httpSessionHelper< / value>
    < / property>
    < / bean>


  4. 在Web脚本中使用新的自定义根对象,例如:

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



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. 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');
    

这篇关于Alfresco-HTTP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆