View Full Version : Access HTTPSession

4 May 2012, 9:34 PM
Hello All,

I've created my application server as RESTful services and manage the session information across requests using HTTPSession. I'd maintained couple values in the HTTPSession which should be used in client side. But i'm not sure, how to get the value from HTTPSession in a ExtJS page.

Thanks for your response.


7 May 2012, 7:01 AM
You can't access HTTPSession from javascript. I think you can use dwr to do it but I'm not expert with the java stuff

8 May 2012, 9:13 AM
You could use an Ext.Ajax.request() to retrieve any server-side session information you need.

I use Java/Spring Framework MVC on the server-side, which uses the Jackson Mapper API to handle JSON views. Below is a sample Request Mapping from a test Controller which returns Session info. It's not a RESTFUL endpoint, but doesn't have to be:

* Returns Session info as a JSON object.
public @ResponseBody Map<String,Object> sessionInfo(HttpSession session)
Map<String,Object> results = new HashMap<String,Object>();
results.put("sessionId", session.getId());
results.put("creationTime", session.getCreationTime());
results.put("maxInactiveInterval", session.getMaxInactiveInterval());
results.put("someArbitraryAttribute", session.getAttribute("someArbitraryAttribute"));
return results;

And here's an Ajax request to retrieve the Session info:

url: 'sessionInfo',
success: function(result, request) {
var json = Ext.decode(results.responseText);
Ext.Msg.alert("Session Info",
"Session ID: " + json.sessionId + "<br/>Some Attribute: " + json.someArbitraryAttribute );
failure: function(result, request) {
var json = Ext.decode(result.responseText);
// assumes json response has a 'msg' property.
Ext.Msg.alert('Error', json.msg);