开发者

passing values from applet to jsp

import java开发者_高级运维.awt.*; 
import java.applet.*;

public class GuiExample extends Applet { 
    Button okButton; 
    TextField nameField;

    public void init() { 
        setLayout(null); 
        okButton = new Button("A button"); 
        nameField = new TextField("A TextField",100); 
        okButton.setBounds(20,20,100,30); 
        nameField.setBounds(20,70,100,40); 

        add(okButton); 
        add(nameField); 
    }

}

how can i pass the value in the textbox to the 'validate.jsp', when the button is clicked? And i also want the browser to go to that jsp page. and continue execution from there? How can i modify the code?


This bit of code might be helpful.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class GuiExample extends Applet { 
    Button okButton; 
    TextField nameField;
    GuiExample currentApplet; // needed for navigation

    public void init() {
        currentApplet = this;
        setLayout(null); 
        okButton = new Button("A button"); 
        nameField = new TextField("A TextField",100); 
        okButton.setBounds(20,20,100,30); 
        nameField.setBounds(20,70,100,40); 

        add(okButton); 
        add(nameField);

        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String text = nameField.getText();
                if (text != null) {
                    try {
                        // modify this to point to your website
                        String address = "http://www.example.com/validate.jsp?p=" + URLEncoder.encode(text, "UTF-8");
                        currentApplet.getAppletContext().showDocument(new URL(address));
                    } catch (Exception ex) {
                    }
                }
            }
        });

    }

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜