В настоящее время я использую JxBrowser в качестве встроенного браузера в моем приложении Java.Я создаю браузер, как показано ниже:
public static void main(String[] args) {
Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.loadURL("https://developer.microsoft.com/en-us/graph");
frame.addWindowListener(new WindowListener() {
@Override
public void windowClosing(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.getCacheStorage().clearCache();
browser.loadURL("https://developer.microsoft.com/en-us/graph");
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
});
}
Когда открывается первый URL-адрес, я вхожу в систему и выбираю, чтобы не оставлять меня в системе. Затем я закрываю это окно, и когда открывается второе окно, я вижу, чтоМой пользователь все еще вошел в систему. Как вы можете видеть, я очищаю кеш и перед открытием URL во второй раз.Но кеш не очищается.