http://localhost:8080/Project/test.jsp (url which hits system1)
http://192.168.1.22:8080/Project/test.jsp (url which hits system2)
jfilechooser code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class BrowsePath extends JFrame implements ActionListener {
JButton button;
JTextField field;
public BrowsePath () {
setVisible(true);
this.setLayout(null);
button = new JButton("browse");
field = new JTextField();
field.setBounds(30, 50, 200, 25);
button.setBounds(240, 50, 100, 25);
this.add(field);
this.add(button);
button.addActionListener(this);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
Chooser frame = new Chooser();
field.setText(frame.fileName);
}
public static void main(String args[]) {
BrowsePath frame = new BrowsePath ();
frame.setSize(400, 600);
frame.setLocation(200, 100);
frame.setVisible(true);
}
}
class Chooser extends JFrame {
JFileChooser chooser;
String fileName;
public Chooser() {
chooser = new JFileChooser();
int r = chooser.showOpenDialog(new JFrame());
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (r == JFileChooser.APPROVE_OPTION) {
fileName = chooser.getSelectedFile().getPath();
}
}
}
我有一个 JFileChooser 代码,当我从本地机器(system1)点击页面时工作正常
上面的jsp页面有一个按钮,点击按钮就会加载。
我尝试了另一种方法,从另一台机器(system2)我尝试通过用 ip 替换 localhost 来访问 url
在上述情况下,它不是在 system2 中运行,而是在 system1 中运行。
- 是否有可能让它在system2中运行?