Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing methods in Java classes from CFOBJECTS

Status
Not open for further replies.

baden

Programmer
Joined
Feb 6, 2002
Messages
125
Location
US
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=&quot;CREATE&quot;
TYPE=&quot;JAVA&quot;
CLASS=&quot;HelloWorld&quot;
NAME=&quot;wlEnv&quot;>

<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=&quot;text/html&quot;;

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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top