小编dca*_*555的帖子

有没有办法只在Tomcat/Wildfly/Glassfish启动时运行方法/类?

我需要删除Tomcat启动时的临时文件,传递到包含临时文件的文件夹位于applicationContext.xml中.

有没有办法只在Tomcat启动时运行方法/类?

java tomcat web-applications startup java-ee

52
推荐指数
2
解决办法
4万
查看次数

Cookie getMaxAge

我无法检索cookie maxage它总是返回-1

创建cookie:

Cookie securityCookie = new Cookie("sec", "somevalue");
securityCookie.setMaxAge(EXPIRATION_TIME);
Run Code Online (Sandbox Code Playgroud)

检索cookie:

Cookie[] cookies = request.getCookies();
if (cookies != null) {
    for(int i=0; i<cookies.length; i++) {
        Cookie cookie = cookies[i];
        if ("sec".equals(cookie.getName())){
            int age = cookie.getMaxAge();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我总是年龄= -1

当我检查firefox cookie到期时,我看到奇怪的日期.

谢谢

java servlets

11
推荐指数
2
解决办法
4952
查看次数

界面问题

假设我有MyInterface接口和2个实现MyInterface的类A,B.
我声明了两个对象:MyInterface a = new A()MyInterface b = new B().
当我尝试传递给函数 - 函数时,doSomething(A a){}我收到一个错误.

这是我的代码:

public interface MyInterface {}

public class A implements MyInterface{}

public class B implements MyInterface{}

public class Tester {

    public static void main(String[] args){
        MyInterface a = new A();
        MyInterface b = new B();
        test(b);
    }

    public static void test(A a){
        System.out.println("A");
    }

    public static void test(B b){
        System.out.println("B");
    }

}
Run Code Online (Sandbox Code Playgroud)

我的问题是,我从一些组件接口,可以是各种类,我需要为每个类编写函数.
所以一种方法是获取接口并检查它是哪种类型.(A的例子)

我想知道其他人如何处理这个问题?

谢谢

java interface

4
推荐指数
1
解决办法
637
查看次数

标签 统计

java ×3

interface ×1

java-ee ×1

servlets ×1

startup ×1

tomcat ×1

web-applications ×1