我想删除JavaFX webengine生成的一些特定的HTTP cookie.Chrome浏览器允许我们删除httponly cookie,这意味着这可以通过编程方式实现.
我可以使用删除所有cookie
java.net.CookieManager manager = new java.net.CookieManager();
manager.getCookieStore().removeAll();
Run Code Online (Sandbox Code Playgroud)
使用此用户也可以从我的应用程序中注销.我希望能够删除除为我的应用程序生成的cookie之外的所有cookie.或者是否可以使用javascript删除相同的cookie.
我正在编写一个基于 Javafx 的 Web 浏览器。我想获取当前在 WebEngine 中打开的网页的标题。谢谢 :)
当我尝试运行我的应用程序时,我收到此错误:
Caused by: java.lang.NullPointerException
at WebOpenController.<init>(WebOpenController.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521)
... 22 more
Run Code Online (Sandbox Code Playgroud)
第19行是这个私有的WebEngine engine = view.getEngine();
这是班级:
public class WebOpenController implements Initializable {
@FXML
private WebView view;
private String link = "http://google.com";
private WebEngine engine = view.getEngine();
@Override
public void initialize(URL location, ResourceBundle resources) {
engine.load(link);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我做WebView view = new WebView时它会工作,但它不会在启动时打开页面
我确实在scenebuilder中设置了fx-id
我正在尝试在横向A4纸上的JavaFX WebView(JavaFX 8_25)中打印HTML页面,但它以纵向打印,字体很小
printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
PrinterJob job = PrinterJob.createPrinterJob(printer);
if (job != null) {
System.out.println(job.getJobSettings().getPageLayout());
webEngine.print(job);
job.endJob();
}
Run Code Online (Sandbox Code Playgroud)
System.out显示纵向方向
纸张=纸张:A4(210 x 297毫米)尺寸= 594.90087890625x841.3598022460938 MM Orient = PORTRAIT leftMargin = 54.0 rightMargin = 54.0 topMargin = 54.0 bottomMargin = 54.0
我发现在横向模式下打印HTML页面的唯一方法是在打印之前调用打印作业的showPageSetupDialog方法.
printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
PrinterJob job = PrinterJob.createPrinterJob(printer);
if (job != null) {
if(job.showPageSetupDialog(null)) {
System.out.println(job.getJobSettings().getPageLayout());
webEngine.print(job);
job.endJob();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我在"页面设置"对话框中选择"横向",则会显示System.out
纸张=纸张:A4尺寸= 210.0x297.0 MM东方= LANDSCAPE leftMargin = 54.0 rightMargin = 53.11810302734375 topMargin = 51.995269775390625 bottomMargin = 54.0
我对话的问题在于我每次都必须设置A4和风景.
我有3个问题: - …