I need to be able to access Java methods within a class from a CFOBJECT type="JAVA"
I've got my class written and compiled:
public class HelloWorld
{
public String writeData()
{
String s1="Data that is being written.";
System.out.println(s1);
return s1;
}
}
================
CF Code:
<!--- Testing Java Objects --->
<CFOBJECT
ACTION="CREATE"
TYPE="JAVA"
CLASS="HelloWorld"
NAME="wlEnv">
<CFSET ctx = wlEnv.writeData()>
<CFOUTPUT>
Testing Java classes with ColdFusion
</cfoutput>
================
WRITEDATA is not a public field or method on this object. Please verify that this class supports this field or method.
The error occurred while processing an element with a general identifier of (CFSET), occupying document position (9:1) to (9:31)....blah blah blah
So... going back to my server-side programming stuff... do I have to create a ServletContext or something like that and call it... something like getServletContext() then refer to methods through that object?
I've tried this:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CFTest extends HttpServlet
{
String mimeType="text/html";
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(mimeType);
PrintWriter out = response.getWriter();
ServletContext sc = getServletContext(); //haven't actually done anything with sc
.
.
.
.
========================
Still can't get it to work!
I've got my class written and compiled:
public class HelloWorld
{
public String writeData()
{
String s1="Data that is being written.";
System.out.println(s1);
return s1;
}
}
================
CF Code:
<!--- Testing Java Objects --->
<CFOBJECT
ACTION="CREATE"
TYPE="JAVA"
CLASS="HelloWorld"
NAME="wlEnv">
<CFSET ctx = wlEnv.writeData()>
<CFOUTPUT>
Testing Java classes with ColdFusion
</cfoutput>
================
WRITEDATA is not a public field or method on this object. Please verify that this class supports this field or method.
The error occurred while processing an element with a general identifier of (CFSET), occupying document position (9:1) to (9:31)....blah blah blah
So... going back to my server-side programming stuff... do I have to create a ServletContext or something like that and call it... something like getServletContext() then refer to methods through that object?
I've tried this:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CFTest extends HttpServlet
{
String mimeType="text/html";
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(mimeType);
PrintWriter out = response.getWriter();
ServletContext sc = getServletContext(); //haven't actually done anything with sc
.
.
.
.
========================
Still can't get it to work!