Javascript onclick  from Java

Hello,
My Google-fu seems to be weak today... I'm writing a simple HTTP parser. It downloads a specific page, parses out the links to the files I'm interested in, then downloads those links. Long story short, certain files on the remote sites are getting corrupted, and it would be nice if my program could handle the cleanup of those files while it is doing the data collection.
The web interface has the following javascript function:
<SCRIPT LANGUAGE="JavaScript">
                  function Delete(What)
                    if (window.confirm("Do you really want to delete this file"))
                      location.href = What;
</SCRIPT>And each file listing has the following HTML:
<IMG SRC="/Images/Trash.gif" OnClick="Delete('/StorageCard2/TEMP21.csv?DELETE')" />Is there some way to call this delete function from within my java program?
I've been trying something like this:
URL url = new URL("http://xx.xx.xx.xx/StorageCard2");
URLConnection uc = url.openConnection();
uc.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(uc.getOutputStream());
writer.write("Delete('/StorageCard2/TEMP21.csv?DELETE')");
writer.flush();I'm probably way off base here, but I can't seem to figure out how to form the correct output, or whether this is even possible. Every combination of URLs I try to submit in the web interface leads to errors. There must be some simple way to simulate clicking those links, or just call the delete command directly.
Can anyone enlighten me as to what I need to do, or where I need to start looking?

And I have to say I'm ultra confused as to why you thought that this would do something good.
URL url = new URL("http://xx.xx.xx.xx/StorageCard2");
URLConnection uc = url.openConnection();
uc.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(uc.getOutputStream());
writer.write("Delete('/StorageCard2/TEMP21.csv?DELETE')");
writer.flush();

Similar Messages

  • Calling javascript method from java

    Hi this is sri,
    I have one doubt on Java Applets "how to call the javascript method from java Applet".Can u give me the complete sample code for one program(both java applet file and html file also)because i can easily understand the programming flow.
    Thanks ,
    Srilekha.

    It's an extremely important skill to learn how to search the web. Not only will it increase your research and development talents, it will also save you from asking questions that have already been answered numerous times before. By doing a little research before you ask a question, you'll show that you're willing to work and learn without needing to have your hand held the entire time; a quality that is seemingly rare but much appreciated by the volunteers who are willing to help you.
    If you've done the research, found nothing useful, and decide to post your question, it's a great idea to tell us that you've already searched (and what methodologies you used to do your research). That way, we don't refer you back to something you've already seen.
    To get you started, here's a link...
    http://www.google.com/search?q=call+java+from+javascript

  • Calling a javascript function from java code and getting tha value in Java

    Hi,
    I would like to call a Java script function confirmRemove() from Java code upon meeting a condition..
    for example the code snippet is:
    if(true){
    // I want to call js confirmRemove() over here. And get the value of variable "answer" in this if block.
    <html>
    <head>
    <script type="text/javascript">
    function confirmRemove() {
         var answer = confirm("Are you sure you want to Delete?")
    </script>
    </head>
    <body>
    <form>...

    Hi,
    Back in 2003 I have used an Applet which contain java code and this java code was calling the java scripts ( different methods, DHTML etc..)
    There was a component developed by NetScape called JSObject I am not sure it there is other third party component other then the JSObject
    look at this article which shows how (based on JSObject)
    [http://java.sun.com/products/plugin/1.3/docs/jsobject.html|http://java.sun.com/products/plugin/1.3/docs/jsobject.html]
    Regards,
    Alan Meio
    London,UK

  • Call Javascript methods from Java methods

    Dear All,
    I have a requirement where I need to invoke Javascript methods from a Java file located in the same machine. Are there any possible solutions for this?
    Regards,
    Alok

    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

  • 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 access a javascript variable from Java?

    Here is my code:
    function validateLoginForm() {
        var username = document.getElementById('un');
        setCookie('un', username, 3650);
        //etc.
    <%   
        HttpSession httpSession = request.getSession();
        httpSession.setMaxInactiveInterval(30 * 60); //30 minutes
        httpSession.setAttribute("un", username); //!prob here - cannot resolve 'username'
    %>
    }...but how do I access the javascript variable 'username' from the Java code?
    Thanks,
    James

    The only way to pass values between JavaScript and JSP is through cookies. It sucks, I know, but right now that is the only option.
    You already are creating a cookie in JavaScript. So go ahead and read it in Java:
    Cookie[] cookies = request.getCookies();
    for(int i = 0; i < cookies.length; i++) {
        Cookie c = cookies;
    if (c.getName().equals("un")) {
    // Do what you need here.

  • Calling JavaScript functions from Java

    Hi,
    I am trying to call the javascript function alert("text message") from a section of Java code.
    I want to do something like below....
    if (balh blah blah...){
    isFound = false;
    alert("Record already exists");
    Dose anyone know how to do this?

    If your Java code is in a JSP page or a Servlet, then yes, but not exactly...
    Since the Java portion of a JSP / Servlet is executed on the server side, there is no way to instantaneously pop up something to the user per se - the code is executed on the server before the output is transmitted to the browser.
    What you could do, however, is to have a JavaScript function defined in your page which would perform the alert:
    <script language="JavaScript">
    function userAlert(message){
        alert(message);
    </script>Then, on the jsp/servlet side, you could perform your if/else check:
    String bodyTag = "<body>";
    String userMessage = null;
    if (balh blah blah...){
       isFound = false;
       userMessage = "Record already exists";
       bodyTage = "<body onLoad=\"userAlert('" + userMessage + "')>\"";
    }This way, as soon as the browser loads the page, it alerts the user with your message.
    Hope this helped,
    -Scott

  • How to manipulate a javascript object in java?

    Hi, I am fiddling with the java scripting interface. As I understand the rhino engine is packaged with the jdk but what I don't understand is how does one reconcile the objects one gets from their engine (e.g. sun.org.mozilla.javascript.internal.ScriptableObject) versus the ones in the rhino api (e.g. org.mozilla.javascript.ScriptableObject)?
    Is the one in the jdk heavily modified or wrappered up to suit their javax.scripting interface?
    More specifically, how do I manipulate javascript objects from java?
    e.g. suppose I have this java code:
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine js = mgr.getEngineByName("js");
    jsEngine.eval("var foo = { x : 1, y : 'hello', z : false };");
    Object o = jsEngine.get("foo");Now o is instanceof sun.org.mozilla.javascript.internal.NativeObject, which is a subclass of a bunch of other classes in the s.o.m.j.i namespace. Being internal I can't use these directly.
    Looking at the Rhino API obviously you normally get a org.mozilla.javascript.ScriptableObject and can call the .get() .getIds() methods. But I don't know how to translate the objects I am getting in my actual java code which uses the jdk engine into org.mozilla.javascript objects.
    Is this even possible? Am I misunderstanding something completely? Should I just be using the rhino js jar and not the javax.scripting interface? If so, for what reason is the javax.scripting interface implemented?

    Assuming that you DO want a deep copy, begin with a constructor that takes another hand.
    public Hand( Hand h ) { ...Then for each instance variable, within that constructor:
    this.instVar0 = h.instVar0;
    this.instVar1 = h.instVar1;
    . . .And last, for every reference, make sure there is a constructor (or copy method for arrays) that itself makes a deep copy:
    this.ref0 = new Ref0Type( h.ref0 );

  • How to provide javascript implementation in java

    hi all
    I am workiing in a project where i need to automate the javascript processing from java.
    suppose if a page has load event and it has some function to do , from java i need to do the functionality for javascript and generate a new DOM for the webpage.
    In this i need to provide the functionality for
    document.write()
    how to provide the write functionality from java.
    suppose
    <form>
    docuement.write("some thing do tadd in form may be some html code");
    </form>
    so how can i add this content in write to a element called FORM and if a page has many forms how to add it to specific one.
    waiting for some hints
    thanking you

    try this link
    http://java.sun.com/products/plugin/1.3/docs/jsobject.html
    import netscape.javascript.*;
    import java.applet.*;
    import java.awt.*;
    class MyApplet extends Applet {
         public void init() {
             JSObject win = JSObject.getWindow(this);
             JSObject doc = (JSObject) win.getMember("document");
             JSObject loc = (JSObject) doc.getMember("location");
             String s = (String) loc.getMember("href");  // document.location.href
             win.call("f", null);                      // Call f() in HTML page

  • "ReferenceError: "myIpAddr"  is not defined, when call JavaScript from java

    Hi developers,
    My java application was trying to issue a http request via proxy auto-config. So, I did below jobs
    1. Read URL of *.pac from registry
    2. Call FindProxyForURL from java, the code is like below
                   ScriptEngineManager factory = new ScriptEngineManager();
                   ScriptEngine engine = factory.getEngineByName("JavaScript");
                   engine.eval(autoProxyScript);
                   Invocable inv = (Invocable) engine;
                   Object obj = inv.invokeFunction("FindProxyForURL",
                             "http://java.sun.com/",
                             "java.sun.com");
    However, I got "ReferenceError: "myIpAddress" is not defined
    I can not change the script on server to add a function like "myIpAddress", I am wordering why IE or mozilla can call it successfully and get proxy server, while Java failed to do that.
    I got a ugly solution by calling "pacparser" by jni. But I really hope I can get a better solution.

    A .pac file is a JavaScript, but it requires some functions to be defined in the executing context to work (i.e. you must define those).
    From the example on the Wikipedia page there's at least "shExpMatch" and "isInNet". "myIpAddress" seems to be another such candidate.

  • Call JavaScript method in FXML from java controller

    I have fxml like
       <fx:root type="javafx.scene.Group" xmlns:fx="http://javafx.com/fxml">
        <fx:script>
            function applyState(oldState, newState)
        </fx:script>   
        ....and controller to it.
    The idea is to move some view logic to fxml file.
    So, when I need to change some view state, I want to call applyState from java code.
    The question is how to do it.
    What I have found:
    We can get
    fxmlLoader.getNamespace().get("applyState")and receive sun.org.mozilla.javascript.internal.InterpretedFunction.
    NetBeans see this class. But while building the project i have an error
    error: package sun.org.mozilla.javascript.internal does not exist
    But this class really exists in rt.jar in JRE.
    After that I have stopped digging into this.
    I suspect that using internal API is not a good idea to call this InterpretedFunction.
    Can somebody suggest how can I make such an invocation?
    Edited by: 940811 on Nov 19, 2012 11:21 PM

    Until JavaFX doesn't expose the ScriptEngine instance of FXMLLoader, there's no way to communicate (Java <-> Javascript) with the <fx:script>.
    But, if you want to rely on a hack, you can do this:
        private ScriptEngine extractScriptEngine(FXMLLoader loader) {
            try {
                Field fse = loader.getClass().getDeclaredField("scriptEngine");
                fse.setAccessible(true);
                return (ScriptEngine) fse.get(loader);
            } catch (IllegalAccessException | NoSuchFieldException | SecurityException ex) {
                Logger.getLogger(BrowserFXController.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }

  • 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.

  • Passing a String from Java to Javascript

    Does anybody know how to pass a string from Java class to Javascript ? Can it be done?

    If you are talking in terms of web terminology...
    People do intialization of page in the following way.
    var java_script_variable = <%=String_variable%>

  • Javascript from Java - calling html control functions

    i have called the attributes of an html control from java using this method
    private JSObject iframeObject;
    iframeObject=(JSObject)win.eval("parent.document.getElementById('"+popupIFrame+"')");
    iframeObject.setMember("src", "../Applet/Popup.html");but how can i call the functions of a control
    for example the focus() function of a textbox or someother controls???

    its ok i got it.
    win.eval() can do it

Maybe you are looking for

  • NHL Game Center

    Hello. I love to watch hockey in my Apple TV with Game Center. My dad also would like to have it, so I went and got him Apple TV, when I was trying to subscribe the NHL it says: it is no longer available... Do you guys know why? It is still working f

  • Change of Local Currency of a subsidiary

    Hi Expets, We are carrying out change of local currency in the begining of the financial year. Master data changes has been done and also currency translation method is assigned in Balance carryforward task. ( I have done local currency channge in th

  • Can I easily add my wife to Find iPhone?

    My wife misplaced her iPhone this weekend and didn't have her computer with her and doesn't own an iPad. she had no way to access Find iPhone app. if we could easily add each other's devices to each other's Find iPhone app, we'd be able to assist eac

  • Field VSBED empty in IDOC DELVRY03

    Hi, I'm generating an outbound idoc DELVRY03 for a delivery. The field LIKP-VSBED is filled. Normally the value in LIKP-VSBED is supposed to be copied in field E1EDL20-VSBED of DELVRY03 idoc. But when the idoc is generate the field E1EDL20-VSBED is e

  • Nokia C3 - Read Chinese charaters and email?

    Is there a way to add chinese language pack on to the Nokia C3 phone? Thank you.