I need to take the data from the browser url and pass this data to an application

Asked

Viewed 125 times

1

I have a java web start application. And I need to make the browser pass the parameters to that application. The javascript function is taking the data from the url but is not yet passing to the other program.

It’s really hard to do that.

The javascript code looks like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
    <title></title>
<script type="text/javascript">
        function OpenInNewTab(url) {
        var win = window.open(url,'_blank');
        win.focus();
        }
</script>   
</head>
<body onload = OpenInNewTab('launch.jnlp')>

<script>    

    function ObterParametroUrl(parametro){
        var parametros = window.location.search.substring(1).split("&");
            for(var i = 0; i < parametros.length; i++){
                var splitParametro = parametros[i].split("=");
                    if(splitParametro[0] == parametro){
                        return splitParametro[1];
                    } 
            }
    }

    var key_text1 = ObterParametroUrl('key_text1');
    var key_text2 = ObterParametroUrl('key_text2');

    if(key_text1 != ""){
        document.UserInput.print(key_text1,key_text2);
    }
</script>
<script>
    alert("text1 " + key_text1);
    alert("text2 " + key_text2);
</script>
</body >

The application that receives this code is like this:

package applet;

import java.awt.*; 
import java.applet.*; 
import java.awt.event.*; 
import java.io.BufferedWriter; 
import java.io.FileWriter; 

  public class UserInput extends Applet implements ActionListener{ 

   TextField key_text1;
   TextField key_text2;
   TextField key_output; 
  Label key_label1,key_label2,key_label3; 
  Button key_button; 
  @Override
  public void start() {
      print(getParameter("string1"), getParameter("string2"));  
  }

  public void init(){ 
    // Create layout   

    setLayout(null); 
    // Add different components to the layout. 
    key_label1 = new Label("Entre password1: "); 
    key_label1.setBounds(20,20,100,20); 
    add(key_label1); 



    key_text1 = new TextField(5); 
    key_text1.setBounds(150,20,100,20); 
    add(key_text1); 

    key_label2 = new Label("Entre password2: "); 
    key_label2.setBounds(20,50,100,20); 
    add(key_label2); 

    key_text2 = new TextField(5); 
    key_text2.setBounds(150,50,100,20); 
    add(key_text2); 

    key_label3 = new Label("Os passwords sao: "); 
    key_label3.setBounds(20,80,130,20); 
    add(key_label3); 

    key_output = new TextField(5); 
    key_output.setBounds(150,80,100,20); 
    add(key_output); 

    key_button = new Button("Get keywords"); 
    key_button.setBounds(150,110,100,20); 
    add(key_button); 
    // Add action listener 
    key_button.addActionListener(this); 
    } 

  public  synchronized void print(String string1, String string2){
      this.key_text1.setText(string1);
      this.key_text2.setText(string2);
    }

  public void actionPerformed(ActionEvent ae){ 
       // Test t = new Test(); 


        // String to get the user input texts 
        String str1= key_text1.getText(); 
        String str2= key_text2.getText(); 
        // Show output on the third text box 
        key_output.setText(str1+"--"+str2); 

        try{                
            // Create out put file 
            FileWriter fstream = new FileWriter("output.txt",true); 
            BufferedWriter out = new BufferedWriter(fstream); 
            // Write to the file 
            out.write("\n"+str1+";"); 
            out.write("\t"+str2+";");            
            //out.write("\t"+str1+",");  
            // Flush the out put to the file 
            out.flush(); 
        } 
        catch (Exception e) 
        { 
            e.printStackTrace(); 
        } 
    } 
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.