Java calling JavaScript

I have a peculiar problem. ..
i need to call a javascript function from jsp and get the string value returned by the function...
i am calling the function like this
<BODY BGCOLOR="#FDF5E6" onload="respPrompt('<%=line%>')"> in jsp file
here is the function..
script language="JavaScript">
function respPrompt(line) {
alert("hello")
var favorite = prompt('Edit the line?',line);
if (favorite) alert("edited line is s: " + favorite);
else alert("You pressed Cancel or no value was entered!");
return favorite;
</script>
i need to get hold of the value "favorite" in the jsp programm...and need to write it to a file...am doing this since i cannot handle files from inside a javascript function....
plz gimme ur suggestions..
thanks
rao

Java runs on the server
javascript runs on the client in the web-browser.
The only communication between the two is via http.
You send a request (with request parameters)
You receive a response in the form of an HTML page.
Thats all the communication there is.
Java can't call javascript, and javascript can't call java.
If you need to prompt the user for info, send back an html page asking for that info, and then have them submit that result back to another servlet/jsp
Cheers,
evnafets

Similar Messages

  • Java Applet call javascript problem

    Hi I have a web page as follow and embedded a applet. The applet call the java script, and instead of showing an alarm, the browser show the javascript code. Is that strange ? Any suggestion for this problem.
    HTML:
    ================================================================
    <HTML>
         <HEAD>
         function ShowEmbd()
              alert("Test Applet call Javascript");
         </SCRIPT>
         </HEAD>
         <BODY>
         <FORM NAME="AppletEmbdStart">
              <OBJECT classid="clsid:48B2DD7B-6B52-4DB0-97C9-ECB940113B47" id="CIVON_DEmbdObj" width="0" height="0"></OBJECT>
              <APPLET code="MyApplet.class" width="0" height="0"></APPLET>
         </FORM>
         </BODY>
    </HTML>MyApplet.java
    =========================================================================
    import netscape.javascript.*;
    public class MyApplet extends javax.swing.JApplet
         private JSObject m_win = null;
         private JSObject m_doc = null;
         public void init()
              getJSWin().call("ShowEmbd", null);
         private getJSDoc()
              if(m_doc == bull)
                   m_doc = (JSObject) getJSWin().getMember("document");
              return m_doc;
         private JSObject getJSWin()
              if (m_win == null)
                   m_win = netscape.javascript.JSObject.getWindow(this);
              return m_win;
    }The page was load and it should call the applet MyApplet. The MyApplet should do the init() method and call the Javascript "ShowEmbd()", BUT, instead of show alert from ShowEmbd(), the browser show the code of ShowEmbd() itself ...... It did not run the javascript and shows the alert ??
    The browser shows a message from status bar "The applet not initial" ???? why ???
    Can anyone help ?!

    On first look:
    I am not sure about the Object Tag, but the Applet Tag requires the MAYSCRIPT attribute before Java can call Javascript.

  • Calling javascript from java

    I am not able get the javascript funtion executed.
    Pl. help me.
    A Javascript function is called from Java by using the showDocument method. A URL is needed with "javascript:" as the protocol.
    [Java applet] import java.applet.*;
    import java.net.*;
    public class inJava extends Applet{
    public void init(){
    String msg = "We will jump to an HTML tag";
    try {
    getAppletContext().showDocument
    (new URL("javascript:doAlert(\"" + msg +"\")"));
    getAppletContext().showDocument
    (new URL("javascript:jumpTo(\"#JUMP\")"));
    catch (MalformedURLException me) { }
    [Javascript and HTML] <HTML><HEAD></HEAD><BODY>
    <SCRIPT>
    function doAlert(s) {
    alert(s);
    function jumpTo(tag) {
    self.location=tag;
    </SCRIPT>
    <APPLET CODE="inJava.class"
    NAME="myApplet" MAYSCRIPT
    HEIGHT=400 WIDTH=10>
    </APPLET>
    <P>
    <A NAME="JUMP">jump here from Java via Javascript</A>
    </BODY>
    </HTML>
    Thanks
    vema

    Vema,
    you cannot go this way. Let me copy/paste the piece of my code:
    JSObject.getWindow( applet ).call( "open", new String[] { /* list of parameters of 'open()' function */ });
    vpanasenko_even

  • How to call javascript from java application

    How can we call a function written in javascript from java application (core java not applet)? How will java identify javascript?
    Is there any such options ?

    Try creating a page called launcher.html (for example). That does this:
    <html>
    <head>
    <script language="javascript">
    windowHandle=window.open("http://www.javasoft.com", "", "height=700,width=1000,status=no,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no,top=5,left=5");
    </script>
    </head>
    </html>Now you launch IE (or whatever) with this page using the Runtime class. After x seconds (after the second window has been launched) try killing the process. Hopefully it will kill the original window you opened and not the window you popup (the one without toolbars etc)
    It might kill both windows but I can't be bothered to test it. If it does you'll have to try and find a workaround.

  • ADF: Can i call javascript function from java clsss method in ADF?

    Hi,
    I want to call javascript function in Java class method, is it possible in ADF? , if yes then how?
    or I need to use Java 6 feature directely?
    Regards,
    Deepak

    private void writeJavaScriptToClient(String script)
    FacesContext fctx = FacesContext.getCurrentInstance();
    ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
    erks.addScript(fctx, script);
    }usage
    StringBuilder script = new StringBuilder();
    script.append( "var popup = AdfPage.PAGE.findComponentByAbsoluteId('p1');");
    script.append("if(popup != null){"); script.append("popup.show();"); script.append("}");
    writeJavaScriptToClient(script.toString());Timo

  • How to call javascript function in back bean of jsf

    hi,
    i am trying to call java script function in back bean but not done. Is there any code for call javascript function in bean file.

    Java runs at server side.
    JSF produces HTML output.
    Server sends HTML output to client.
    Java stops running.
    HTML runs at client side.
    JS starts to run in HTML.
    Clear? Java is a server side language. JS is a client side language. To run JS using JSF, simply print it out to the HTML so that it get invoked when the HTML runs.

  • Calling JavaScript function from Servlet ?

    I have a Servlet that needs to call a general purpose JavaScript function to retrieve some data. The JavaScript function sits in a file on the web server called general.js.
    How can I call this function from my servlet to retrieve an integer result ?
    Sarah.

    http://developer.netscape.com/docs/manuals/js/client/jsguide/index.htm
    Look for Java to JavaScript communication.

  • How to call javaScripts in pfr() of CO

    HI all
    I want to call a script in prf() of CO
    that script is already at same page
    how can I call?

    hi,
    you can inject the javaScript in as follow for example you have TextIputField with enternal name EnterValue. write the following code at processRequest() method.
    String javaS = "alert(\"JavaScript in Action \\n\");\n";
    OAMessageTextInputBean EnterValue = (OAMessageTextInputBean)webBean.findChildRecursive("EnterValue");
    EnterValue.setOnBlur(javaS);
    this will show an alert when user tab out of the current field.
    Note: in processFormRequest() you can't call beans setter methods.
    Regards,
    Haroon.
    Edited by: Haroon Afridi on Apr 28, 2011 10:00 PM

  • Java and javascript cookies

    Hi
    i create a cookie called "SaveState" from javascript in my JSP dynpage.
    I want to read this from java (NOT JAVASCRIPT).
    Is this possible?
    if not, is there some kind of portal memory I can use to pass values between java and javascript?
    thanks
    Anton Kruse

    Hi,
    <b>Domain</b>
    The "domain" parameter is used to set the domain the cookie is accessable to. A path can be set for your own domain only and the domain path must include at least two periods (.domain.com). It must match your server's domain name. Therefore cookies are not a security risk since only the server that sets them can use them.
    Check this to know more about cookies:
    http://www.comptechdoc.org/independent/web/cgi/javamanual/javacookie.html
    If you still have questions, I will suggest to google on cookies.
    Greetings,
    Praveen Gudapati

  • How call javascript method from parent window to iframe

    hi....
    i need to call javascript a method which located in iframe..
    in my java script file i used like this.
    window.frames[0].getHtml();
    it will working in IE but mozilla is not supporting
    pls help me..
    thanks
    Edited by: fsfsfsdfs on Nov 7, 2008 1:02 AM

    Sorry, Javascript is not Java and for sure not JSF.
    Repost the question at a forum devoted to Javascript.
    There are ones at [webdeveloper.com|http://www.webdeveloper.com] and [dynamicdrive.com|http://www.dynamicdrive.com].
    I can give you at most one hint: [DOM reference|https://developer.mozilla.org/en/DOM].
    Good luck.

  • Use plsql within java (or javascript) programs

    hi,
    to interface with oracle db, I've always used PLSQL blocks within programs written in C language but now I've to insert PLSQL blocks in java or javascript language
    I don't know if it's possibile and I don't know how to do it
    may someone explicate it to me?
    thanks a lot!

    mfran2002 wrote:
    hi,
    to interface with oracle db, I've always used PLSQL blocks within programs written in C language but now I've to insert PLSQL blocks in java or javascript language
    I don't know if it's possibile and I don't know how to do it
    may someone explicate it to me?
    thanks a lot!There is no pre-processor in the Java standard packages (don't know if there is one out there somewhere, but I imagine that there probably is) as there is for Pro*C. Oracle have one in store??? ... hope so.
    So in Java the SQL (including function calls) is built as Strings, which are then fed as arguments to the execute methods of Statement, or to the PreparedStatement itself - that tutorial will spell this all out well.
    So the SQLs can be static or build dynamically.
    ~Bill
    Also ... you can store Java stored procedures in the Oracle DB, wrapped as PL/SQL functions and then call them as such.

  • How to call javascript function with dynamic data in display tag

    Hi,
    Iam new to pagination concept. Iam using display tag to display rows in jsp by strtus.
    I have a problem when calling the javascript function using ahref in attribute in display tag.
    <bean:define name="form1" property="EditDetails.List" id="ListDisplay"/>
    <display:table name="pageScope.ListDisplay" cellpadding="0" cellspacing="1" pagesize="10" partialList="false" size="listSize" requestURI="">
    <display:column property="poNo" href='javascript:searchEditDetails("./submitOrder.do? actionID=getMISLoadEdit&poNumberSel=<%=((com.po.bean.EditDetails)poListDisplay).getNo()%>&statusIdSelected=<%=((com.po.bean.EditDetails)ListDisplay).getStatusId()%>")'
    title="Number"/>                         
    <display:column property="strDate"title="Date" />
    <display:column property="orderValue"title="Order Value(INR)"/>
    <display:column property="stringRequestedDeliveryDate"title="Suggested Delivery Date"/>
    <display:column property="statusDescription" title="Status" />
    </display:table>
    The above code display the data in row format is working fine when I click the No It thow javascript error and its not redirecting to the other page.
    When I try this with ordinary struts its working fine the code is:
    <logic:iterate id="polist" name="Form1" property="EditDetails.List" indexId="i" type="com.bean.EditDetails">
    <tr>
    <td ><a href="javascript:searchEditDetails("./submitOrder.do?actionID=getMISLoadEdit&NumberSel=<%=((com.bean.EditDetails)polist).getNo()%>&statusIdSelected=<%=((com.bean.EditDetails)polist).getStatusId()%>")"><html:hidden name="polist" property="No" write="true" /></a>     </td>
    <td><html:hidden name="polist" property="strDate" write="true" /></td>
    <td><html:hidden name="polist" property="orderValue" write="true" /></td>
    <td><html:hidden name="polist" property="stringRequestedDeliveryDate" write="true" />     </td>
    <td><html:hidden name="polist" property="statusDescription" write="true" /></td>
    </tr>
    </logic:iterate>
    Please help me how to call javascript with dynamic data.
    Thanks in advance

    The ADF Mobile Container Utilities API may be used from JavaScript or Java.
    Application Container APIs - 11g Release 2 (11.1.2.4.0)

  • How to call javascript function?

    Hi,
    How to call javascript function for SAP button
    control onclick event?
    Thanks in advance.

    Hi Sundar,
      u can call java script  in design mode.
      Add this code in ur design part inside body and call the function as
    <sap:button id="a" onSelect="javascript:go();"
    Add inside body:
      <script language="javascript>
    function go(){
    alert("hai");
      </script>
    Regards,
    Vinoth.M

  • Applet fails to call Javascript methods

    I'm trying to implement round-trip javascript to Java to Javascript using LiveConnect, and having a lot of trouble in Firefox. It works perfectly in IE 6. In Firefox, I can successfully call a method of an applet, and get a return value. I have not been able to get the applet to call a Javascript method. I have tried using both the call and eval methods of the JSObject with no luck. Below is my code. Any suggestions would be appreciated.
    Thanks.
    import java.applet.Applet;
    import java.awt.*;
    import netscape.javascript.*;
    public class test extends Applet {
         String message="Hello Universe!";
         JSObject proxy;
         public void paint(Graphics g) {
              g.drawString(message, 20, 20);
         // pass in ref to JS object on which to call method
         public Boolean handshake(JSObject jso) {
              proxy = jso;
              // try just calling straight eval
              proxy.eval("alert('eval')");
              // set up args object to pass to js method
              Object[] args = new Object[1];
              args[0] = "handshake";
              // call method of js object 2 different ways
              proxy.call("callback", args);
              proxy.eval("o.callback('eval')");
              return true;
         // update java display to show JS to J communication
         public void setMessage(String message) {
              this.message = message;
              repaint();
    <html>
    <head>
         <script>
              // js object to receive calls from applet
              function obj() {};
              obj.prototype = new Object();
              obj.prototype.callback = function(arg) {
                   alert("callback: " + arg);
              function doit() {
                   var a = gebi("myApplet");
                   a.setMessage("Goodbye World!");
                   o = new obj();
                   // test that js method works (it does)
                   o.callback("local");
                   // call applet method which should call back to js method
                   var there = a.handshake(o);
                   // show return value from applet method call
                   alert("there: " + there);
              window.onload = doit;
         </script>
    </head>
    <body>
         <applet
              id="myApplet"
              code="test"
              width="400"
              height="50"
              mayscript="mayscript">
         </applet>
    </body>
    </html>Results:
    In both IE and Firefox, the string shown by the applet switches to "goodbye world", the local call to the callback function works, and the call to handshake returns true.
    That's all that works in Firefox.
    In IE, the various calls to the callback method, and to the alert method of the Javascript all work.
    The results are the same whether I run the HTML page as a local file, or through IIS.
    I have also noticed that Firefox seems to hang up, crash, and just have a lot of problems dealing with this code.
    Finally, I am running all of this on XP professional SP1 with J2SE 1.5.0_04-b05 and Firefox 1.07

    Hi,
    Thanks for all your replies. Does this work on Java 5 too? Could you please share the complete code snippet which makes it work? I tried working on yours but no success.
    Regards,
    Alok

  • Java call rfc check in original:error while checking in and storing.

    hi,experts.
    java call rfc check in original:error while checking in and storing. BAPI in the RFC is "BAPI_DOCUMENT_CJANGE2",
    the RFC was fine in SE37 and calling by Visual Basic. and in java,when mConnection.setAbapDebug(true), and  runing by step and step, was fine too.
    if mConnection.setAbapDebug(false) in JAVA, up error in title was displayed.
    what cause this error?
    Best Regards.

    Hi Priya
    Please use Su53 after getting the error and find any authorization is missing for the user..
    S_GUI Full Authorization is required..
    Since by giving BASIS Authorization its rectificed, then it shud be mostly due to Auth issues only
    Regards
    Aby

Maybe you are looking for