Skip to main content
January 25, 2012
Question

share session data between coldfusion and spring 3 code

  • January 25, 2012
  • 1 reply
  • 854 views

We have an application written in coldfusion using the fusebox framework and running on the jrun (coldfusion 9) app server.

A couple of new screens have been written in java using the spring 3 framework.  I am trying to tie the new screens in the the existing coldfusion screens.

One of the new screens, on submit, has to leap back across to one of the screens written in coldfusion. 

The problem is that the new Spring 3 MVC page replaced one of the existing coldfusion screens, and the coldfusion screen that I'm trying to redirect to depends on session variables that would have been set by the screen that has been replaced. 

I found all kinds of information on the internet that describes how to share session data between J2EE and Coldfusion.  However, whatever I set inside the spring 3 controller does not make it across to coldfusion and visa versa. 

I followed the procedure for configuring the coldfusion administration screen to use J2EE sessions and to set the properties in Application.cfm to name the application and to use session variables. However, even after all of that, the session

data seems to be mutually exclusing between coldfusion and Spring 3.

Here is the coldfusion code

<LINK REL="stylesheet" HREF="../cp.css" TYPE="text/css">

<cfoutput>

<br />

<br />

<div style="margin-left:200px;margin-top:100;">

<h1>Step 1 Part B </h1>

<cfset REQ=createObject("Java","javax.servlet.http.HttpServletRequest")>

<cfset SES=createObject("Java","javax.servlet.http.HttpSession")>

<cfset MAP=createObject("Java","java.util.Map")>

<cfset REQ = GetPageContext().getRequest()>

<cfset SES = req.getSession()>

<cfset MAP = ses.getAttribute("SPRINGSESSION")>

<br />

   <h2>Data</h2>

   <ul style="list-style:none;">

       <li>ID: #MAP.ID#</li>

    <li>Person filling out form: #cookie.First_N# #cookie.Last_N#</li>

    <li>Supervisor:  #MAP.First_N# #MAP.Last_N#</li>

    <li>Title: #MAP.title#</li>

   </ul>

...(blah, blah)

Here is the spring 3 controller:

package springapp.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpSession;

...(blah blah)

@Controller

@9974604("session")

public class MyFormController

{

    // Dependency Injections

... (blah, blah)

    @RequestMapping(value = "/myForm", method = RequestMethod.GET)

    public ModelAndView getPage(@RequestParam(value = "id", required = false) String id)

    {

        (some code here)

        return mav;

    }

    @RequestMapping(value = "/myForm", method = RequestMethod.POST)

    public String savePage(HttpServletRequest req, FormObj formData)

    {

        HttpSession session = req.getSession();

        Map<String,String> map = (Map<String,String>) new HashMap<String,String>();

        map.put("ID", String.valueOf(formData.getId()));

        map.put("First_N", formData.getFirstName());

        map.put("Last_N", formData.getLastName());

        map.put("Title", formData.getTitle());

        session.setAttribute("SPRINGSESSION", map);

        return "redirect:http://localhost/legacyapp/index.cfm?fuseaction=do.form2";

    }

}

What is happening is that I get an error on the coldfusion side that says "MAP.ID" not found, which means I'm getting an empty map object.

I also tried from the spring 3 controller to get the existing session from coldfusion using the application name rather than setting a new one called "SPRINGSESSION", but I just get null.

Map<String,String> map = (Map<String,String>) session.getAttribute("myColdfusionAppName");

Anyone have any ideas how to make the session visible by both apps or any other effective way of sharing the data? 

My thought was to use session variables because that is what the coldfusion code is already accessing rather than writing all new code for accessing a database.

Any ideas or suggestions?

Thanks!

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    January 26, 2012

    A few suggestions:

    1) It is sufficient to configure the use of J2EE sessions in the Administrator, whereby ColdFusion will create the JsessionID automatically. You shouldn't set the session again manually.

    2) The JsessionID identifier that ColdFusion creates in (1) is the value that you have to share with any servlets that you call from a ColdFusion page. Not the other way round. That is, the Spring application should not be sending session identifiers to ColdFusion.