Servlet calls java function
hi
is there any way we can call a normal java function directly from a servlet? here's what i meant:
public void service(ServletRequest request, ServletResponse response)throws IOException{
some statements....
pw.println("<input type=button action='call javafunc(arg1,arg2)'>"); //something like this
int javafunc(arg1,arg2){
do some processing here..
if anyone does get what i'm trying to do, how do I actually get them working? because i know the code above won't work..
any help are greatly appreciated. thanks in advance.
If you are asking whether you can call a Java method from a servlet, sure you can. Servlets are written in Java themselves. Of course you can't have a method inside a method, if that's the problem you are referring to. Just put your javafunc method outside your service method.
However you can't have an action on the client side call that method. In fact an action on the client side can't use Java code at all. Javascript, yes, but not Java.
Similar Messages
-
How to call java function in javascript
Hello Everyone,
Can anyone tell me solution that:
How to call java function in javascript?
Thanks,
VIDsYou can't since Java is running on the server and javascript is running in the browser long after the Java side of things has finished executing. Assuming you're not talking about an applet here.
But you can make calls back to the server through Ajax. All you need is something like a servlet on the receiving end which you can invoke through Ajax; from that point you can execute any Java code you want. -
ABAP Calling JAVA Function or Method
Hi Friend,
I need help in how to proceed using ABAP and Call JAVA Function . I know that we need to use RFC enabled Function modules. I was able to connect using JAVA Connector which was provided by SAP For communicating with JAVA Apps. The approach for connecting the JAVA to SAP is working fine. But I have browsed through various website but failed to find any information.Now i am looking forward to help from you friends to solve my problems .
The Requirement is mentioned below:-
1. Prerequiste for SAP ABAP calling a third Party software which is working in JAVA Platform (like any middle ware which might be hardware or software).
2. Sample Code like calling a Text ' Hello to the world calling JAVA from ABAP'.
3. Steps and process so that it would be helpful.
Timely help would be appreciated.
Rajiv Christopher.1.Middleware is JCO RFC provider it comes with SAP so no need any third party Adapter.
2.
" The ECHOTXT parameter should contain the text of REQUTXT.Information on
" calling the function module should be returned in RESPTXT, indicating, for
" example, in which system and when the function module call was processed.
data:ECHOTEXT type SY-LISEL,
RESPTEXT type SY-LISEL.
CALL FUNCTION 'STFC_CONNECTION' DESTINATION '<Your JCO destination name>' " which one you have developed in SM59 as TCP/IP
EXPORTING
requtext = 'ABAP Calls JAVA'
IMPORTING
ECHOTEXT = ECHOTEXT
RESPTEXT = RESPTEXT.
if sy-subrc = 0.
WRITE:/'---------------------------------------------------------------------'.
WRITE: / 'establish a link to the ABAP application server with logon data'.
WRITE:/'---------------------------------------------------------------------'.
write:/ ECHOTEXT .
else.
WRITE:/'---------------------------------------------------------------------'.
WRITE: / 'Not establish a link to the ABAP application server with logon data'.
WRITE:/'---------------------------------------------------------------------'.
endif.
Check the sample code and Let me know will you get ECHOTEXT ?
Kanagaraja L
Edited by: Kanagaraja Lokanathan on Jan 6, 2010 1:27 PM -
Call Java functions in a C DLL
Hi,
I am develop a dynamic link library in C on AIX that will internally call java functions using JNI. This libaray will be finally used by other C Executable.
There is only one function in C code i.e. Connect. This function internally use JNI and call java functions. Now while compiling I am facing problems. I think that there is some problem with my makefile.
The make file is given hereunder:
JAVA_HOME = /usr/java14
JAVA_INC = $(JAVA_HOME)/include
CC = cc
LD = cc
# Flags to create a dynamic library.
DYNLINKFLAGS = -G -ostdlib -bnoentry -bM:SRE -brtl -bE:Interface.exp
# files removal
RM = rm -f
#------------------------------------- Libs -----------------------------------#
JAVALIBS = -L$(JAVA_HOME)/jre/bin/classic/
LIBS = -ljvm -lpthread -lxnet -lnsl -lm -ldl
#-------------------------------- Dependency rules---------------------------#
# shared library files
LIB_FILES = Interface.a
#-------------------------------------OBJs-------------------------------------#
# shared libraries object files
LIB_OBJS = Interface.o
all: $(LIB_FILES)
# create our librarys
Interface.a: Interface.o
$(LD) $(DYNLINKFLAGS) $(JAVALIBS) $(LIBS) $(LIB_OBJS) -o $@
# compile C source files into object files.
%.o: %.c
$(CC) $(DYNLINKFLAGS) -L$(JAVA_INC) -c $<
# clean everything
clean:
$(RM) $(LIB_OBJS) $(LIB_FILES)
# clean the library's object files only
cleanlibobjs:
$(RM) $(LIB_OBJS)Now the problem is that the size of the Interface.a file is very small only 552 bytes. whereas the size of Interface.o file is 34428. Which clearly indicates that the problem is with the Interface.a file i.e during linking.
Can any body help me to figure out the problem.
Regards,
Ahmad Jalil QarshiI guess, you are better off to ask this question in a C forum. This is a Java forum, you know.
-
How to call java function from PL/sql in oracle applications
I am trying to call a java function from plsql procedure. Can any one explain how to call java function, and in which directory I have to store my java function in oracle applications. Do I need to register that java function from Application developer.
Thanks
Kranthihttp://www.oracle.com/technology/tech/java/jsp/index.html
Good Luck,
Avi. -
Calling Java function thru PL-SQL
Dear all
As i am New to JAVA ,Can you plz Tell how we can call Java function thru PL-SQL?
To activate / deactivate function will be called from the database plug-ins. No need for GUI.
Using the URL ,The objective is to automate this function.
Many Thanks
Edited by: khaja on Jan 18, 2009 12:50 PMKhaja,
Please refer to http://download.oracle.com/docs/cd/B19306_01/java.102/b14187/chthree.htm#CACICFFB
Please try to avoid asking questions for which you can easily find the answer yourself.
I had to look this up, and found it in less than 2 minutes.
Sybrand Bakker
Senior Oracle DBA -
Call Java function from multithreaded VC++ application
Friends, I want to call Java function from two threads of a single VC++ application. I can call it from single thread but when I call it from another thread also, JNI_CreateJavaVM() replies with an error.
Please......help meYour posting is ambiguous. My impression is that you have two threads, both trying to create a java VM?
-
How to call java function with parameter from javascript in adf mobile?
how to call java function with parameter from javascript in adf mobile?
The ADF Mobile Container Utilities API may be used from JavaScript or Java.
Application Container APIs - 11g Release 2 (11.1.2.4.0) -
Calling java functions from c++
I want to start my program from visual c++ then, call java functions and then calling c++ function. How can i do this?
Yet another cross-poster: [Calling java functions from c++|http://www.java-forums.org/new-java/12597-calling-java-functions-c.html]
-
Problem while calling java function from html
when i tried to call a java function from html i'm getting an error
object don't support this property.
what could be the reason.
This is my html.
I got this from this forum only.
My applet is accessing the system property "user.home".
I ran it in IE
<DIV id="dvObjectHolder">Applet comes here</DIV>
<br><br>
<script>
if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1){ // set object for Netscape:
document.getElementById('dvObjectHolder').innerHTML = " <object ID='appletTest1' classid=\"java:test.class\"" +
"height=\"0\" width=\"0\" onError=\"changeObject();\"" +
">" +
"<param name=\"mayscript\" value=\"Y\">" +
"<param name=\"archive\" value=\"sTest.jar\">" +
"</object>";
}else if(window.navigator.appName.toLowerCase().indexOf('internet explorer')!=-1){ //set object for IE
document.getElementById('dvObjectHolder').innerHTML = "<object ID='appletTest1' classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"" +
" height=\"0\" width=\"0\" >" +
" <param name=\"code\" value=\"test.class\" />" +
"<param name=\"archive\" value=\"sTest.jar\">" +
" </object>"
</script>
<LABEL id="lblOutputText">This text will be replaced by the applet</LABEL>
<BR>
<input value="Javascript to java" type=button onClick="document.appletTest1.fromJavaScript()">I tried this example using the repy given to an earlier post.
But its not working with me.
What i did in addition was adding plugin.jar to classpath to import netscape.javascript.*;
Let me add some more details
1) I'll add the stack trace
2) my java progrma
3) batch file to sign the applet.
1) This is the stack trace i don't know whether u will undertand this
load: class test.class not found.
java.lang.ClassNotFoundException: test.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\FastranJava\AppletObject\bin\test\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more
Exception in thread "Thread-5" java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
2) Java Program
import netscape.javascript.*;
import java.applet.*;
public class test extends Applet
private JSObject win;
private JSObject outputLabel;
private boolean buttonFromJavaClicked=false;
checkJavaScriptEvent evt=new checkJavaScriptEvent();
public void init()
try
evt.start();
win=JSObject.getWindow(this);
outputLabel=(JSObject)win.eval("document.getElementById('lblOutputText')");
outputLabel.setMember("innerHTML", "<center><h1>From Init<br>Your Home directory" + System.getProperty("user.home") + "</h1></center>");
catch(Exception e)
e.printStackTrace();
public void fromJavaScript()
buttonFromJavaClicked=true;
public void fromJavaScript2()
System.out.println("Started Form JavaScript2");
try
String strLbl="<center><h1>From JavaScript<br>Your Homedir:" + System.getProperty("user.home") + "</h1></center>";
outputLabel.setMember("innerHTML", strLbl);
catch(Exception e)
e.printStackTrace();
class checkJavaScriptEvent extends Thread
public void run()
while(true)
if(test.this.buttonFromJavaClicked)
System.out.println("OK buttonfromjava is true");
test.this.buttonFromJavaClicked=false;
fromJavaScript2();
try
Thread.sleep(3000);
catch(Exception e)
e.printStackTrace();
3) Batch file
del *.cer
del *.com
del *.jar
del *.class
javac -classpath ".;C:\Program Files\Java\jre1.5.0_06\lib\plugin.jar" test.java
keytool -genkey -keystore harm.com -keyalg rsa -dname "CN=Harm Meijer, OU=Technology, O=org, L=Amsterdam, ST=, C=NL" -alias harm -validity 3600 -keypass password -storepass password
jar cf0 test.jar *.class
jarsigner -keystore harm.com -storepass password -keypass password -signedjar sTest.jar test.jar harm
del *.class -
Can we call java function in java script????
hello
please tell me can i call a java function through java script function in jsp???of course not. JavaScript is interpreted by the client (web browser) while the Java code in a JSP resides on the server. don't confuse the web application's architecture.
robert -
Calling JAVA Functions from XSLT
Hi,
I am trying to invoke a Java Extension Function from a XSLT. I added both the class file and the XSLT file to a folder, then zipped the entire folder and uploaded into the Archive for my Interface MApping.
The CLASS gets loaded but the runtime engine gives an error when calling the JAVA Function.
Here is what it says:
Creating mapping sequence with 2 steps. --- Creating Java mapping Deliveries/stringHandler --- Creating mapping sequence with 2 steps. --- Creating XSLT mapping Deliveries/test1 --- Using MappingResolver with context URL /sapmnt/XD1/global/xi/mapping/http%3A%2F%2Fwolterskluwer%2Ecom%2Fxi%2F wk_midas_deliveries%2Ftest/cd2e6820267511d9cb52c3c5143c3524/ --- Loaded class Deliveries.stringHandler --- com.sap.aii.ibrun.server.map.MappingRuntimeException: at com.sap.aii.ibrun.server.map.MappingRuntimeException.code_STYLESHEET_OR_CLASS_NOT_FOUND(MappingRuntimeException.java:91) at com.sap.aii.ibrun.server.map.RUMappingJava.instantiate(RUMappingJava.java:168) at com.sap.aii.ibrun.server.map.RUMappingJava.execute(RUMappingJava.java:41) at com.sap.aii.ibrun.server.map.RUSequence.execute(RUSequence.java:50) at com.sap.aii.ibrun.server.map.RURunner.run(RURunner.java:58) at com.sap.aii.ibrun.server.map.RUManager.run(RUManager.java:66) at com.sap.aii.ibrun.sbeans.map.MappingRequestHandler.handleRequest(MappingRequestHandler.java:67) at com.sap.aii.ibrun.sbeans.map.MappingServiceImpl.processFunction(MappingServiceImpl.java:83) at com.sap.aii.ibrun.sbeans.map.XMappingServiceObjectImpl0.processFunction(XMappingServiceObjectImpl0.java:24) at com.sap.aii.ibrun.sbeans.map.MappingServiceKey.processFunction(MappingServiceKey.java:10) at java.lang.reflect.Method.invoke(Native Method) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.invokeBean(RFCDefaultRequestHandler.java:83) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.handleRequest(RFCDefaultRequestHandler.java:50) at com.inqmy.services.rfcengine.RFCJCOServer.handleRequest(RFCJCOServer.java:69) at com.sap.mw.jco.JCO$Server.dispatchRequest(Unknown Source) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.nativeListen(Native Method) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.run(Unknown Source) at java.lang.Thread.run(Thread.java:513) --
Any help or suggestions to solve this problem would be greatly appreciated.
Thanks
AHi,
Thanks for looking into this.
1. I have verified that the path in the zip file is correct i.e com/sap/test/stringHandler.class
2. test1.xsl is in the root folder i.e No path.
3. I see the Message in the stacktrace saying "Loaded Class com/sap/test/stringHandler.class " but after that I get a runtime MApping Error and it says "CLASS_NOT_FOUND".
Can you please tell me why is this happening?
Thanks
A -
Newbie Help: Calling Java function from XSLT
Hi everyone!
I am trying to call a java function from my XSL file. like...
<xsl:stylesheet version="1.0"
xmlns:java="http://xml.apache.org/xslt/java"
xmlns:fn="http://www.my.com/xslt"
exclude-result-prefixes="java fn">
<xsl:variable name="embeddedpic"
select="formData/instance/EmployeePicture" />
<xsl:variable name="pic" select="fn:com.my.utils.ConversionUtils.base64DecodeString($embeddedpic)"/>I am getting this exception in calling the above java function from my XSLT (XalanXPathException: The function number 'http://xml.apache.org/xslt/java:com.my.utils.ConversionUtils.base64DecodeString' is not available.)I have the function lib file in my classpath but still i am getting this error. Any info is highly appreciated.
ThanksTry this.
<?xml version="1.0" ?>
<xsl:transform version="1.0" xmlns:fn="com.my.utils" >
<xsl:variable name="pic" select="fn:ConversionUtils.base64DecodeString($embeddedpic)"/>
etc.
as long as your code is in the classpath it should find it.
Henock. -
Hi,
I am trying to call a small java function in XSL but while performing transformation I get following error
"Function not in namespaceError in XPath expression, Function not in namespace"
I am performing following steps:
1. Java class file placed in class path and classpath is set. Java class is a simple file with no main() function. There is only one function called calculate()
2. Defined a namespace in XSL
3. Calling a function from class file in XSL
My XSL looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fib="java:FibonacciNumber"
extension-element-prefixes="fib" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/" >
<xsl:value-of select="fib:calculate(number(.))"/>
</xsl:template>
</xsl:stylesheet>
Can someone please point out what I am missing out here?
Regards,
NitinPlease refer
http://www.devx.com/Java/Article/31675 -
Hi,
I am trying to call a small java function in XSL but while performing transformation I get following error
"Function not in namespaceError in XPath expression, Function not in namespace"
I am performing following steps:
1. Java class file placed in class path and classpath is set. Java class is a simple file with no main() function. There is only one function called calculate()
2. Defined a namespace in XSL
3. Calling a function from class file in XSL
My XSL looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fib="java:FibonacciNumber" extension-element-prefixes="fib" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/" >
<xsl:value-of select="fib:calculate(number(.))"/>
</xsl:template>
</xsl:stylesheet>
Can someone please point out what I am missing out here?
Regards,
NitinLooks like you are using the Xalan convention for java protocol in namespaces.
In Oracle XDK you need to use:
xmlns:fib="http://www.oracle.com/XSL/Transform/java/FibonacciNumber"
Assuming your class is in the default package.
If it is in a package you need the fully qualified name:
xmlns:fib="http://www.oracle.com/XSL/Transform/java/com.foo.FibonacciNumber"
See for example http://www.devx.com/Java/Article/31675/0/page/1
or http://download-east.oracle.com/docs/cd/B14099_11/web.1012/b14033/adx04xsj.htm#i1023310
For more discussion on how hard it is to craft portable functions with Oracle,
see Re: EXSLT implementation
Mik
Maybe you are looking for
-
Robohelp 7 HTML cannot get files with accented characters in the name
The files are added without a problem but "Get" operation returns error "invalid file name" Example of the file name Le_système.htm or Aperçu_du_système.htm
-
Hello All, I need to add a second drive to my powermac g5. I have the stock 80gb drive in there and want to get the largest, fastest drive the g5 will accept for the second slot. Does anyone know what the largest drive size i can put in there is? 500
-
Dynamic user events freeze user interface
Hi all, I am having problem with dynamic user events. Dynamic user event is registered to the event structure, and many dynamic user events come in very fast, about every 30 ms. It freezes up the user interface, no response to mouse and keyboard, eve
-
I have large text files that I have to convert into tab delimited text to import into excel. The information in each "column" is just separated by multiple spaces (so it is not actually a true column) with a paragraph return at the end of each entry.
-
ECM - Comp process (IT0759) Calc Base and Currency changed
We just went live with ECM (26-Feb-2007). I have found several instances where the IT0759 was created correctly but now the Calculation Base is zero and the Currency is blank. A review of the change log shows the change from a correct non-zero Calc