Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Vaadin获取init外部字符串的值_Java_Vaadin - Fatal编程技术网

Java Vaadin获取init外部字符串的值

Java Vaadin获取init外部字符串的值,java,vaadin,Java,Vaadin,我是否可以在init方法之外检索字符串“code”的值,并在其他方法中使用它 如果是,如何进行 谢谢你的帮助 编辑:字符串必须在init方法中 代码: 您可以将代码存储为实例变量: public class VaadinApplication { private String code = null; // <-- Instance variable protected void init(VaadinRequest request) { main();

我是否可以在init方法之外检索字符串“code”的值,并在其他方法中使用它

如果是,如何进行

谢谢你的帮助

编辑:字符串必须在init方法中

代码:


您可以将代码存储为实例变量:

public class VaadinApplication {

    private String code = null; // <-- Instance variable

    protected void init(VaadinRequest request) {
        main();
        String code = request.getParameter("code");
        if (code != null){
            this.code = code; // <-- store code here
            System.out.println("Code: " + code);
            next();
    }

    protected void otherMethod() {
        this.code; // <-- Get code here and use it
        //...
    }
}
公共类应用程序{

private String code=null;//您提供的代码是您自己的类吗?@JamesB是您创建新的Vaadin应用程序时默认编写的。但是类中的代码是我的。您可以向这个类添加代码吗?@JamesB是的,我可以。您有什么建议吗?
public class VaadinApplication {

    private String code = null; // <-- Instance variable

    protected void init(VaadinRequest request) {
        main();
        String code = request.getParameter("code");
        if (code != null){
            this.code = code; // <-- store code here
            System.out.println("Code: " + code);
            next();
    }

    protected void otherMethod() {
        this.code; // <-- Get code here and use it
        //...
    }
}