Alfresco-HTTP会话 [英] Alfresco - HTTP Sessions
问题描述
尝试通过QuickStart上的Javascript Webscript访问HTTP会话。
我无法在将元素保存到每个http会话的某些私有对象中找到任何帮助。 / p>
有人知道任何解决方案吗?
-
创建一个自定义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;
}
}
}
-
编译并打包此类进行jar存档并将其复制到Share(或基于Surf的应用程序)。
-
在spring-surf-script-services-context.xml中注册此类,例如:
< bean id = exampleExtension parent = baseScriptExtension
class = pl。 test.HttpSessionHelper>
<属性名称= extensionName>
< value> httpSessionHelper< / value>
< / property>
< / bean>
-
在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?
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; } } }
Compile and package this class to jar archive and copy it to Share (or Surf based application).
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>
Use your new custom root object in webscript, for example:
var paramName = httpSessionHelper.getFromSession('paramName'); httpSessionHelper.setInSession('paramName','paramValue');
这篇关于Alfresco-HTTP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!