我需要删除Tomcat启动时的临时文件,传递到包含临时文件的文件夹位于applicationContext.xml中.
有没有办法只在Tomcat启动时运行方法/类?
我无法检索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到期时,我看到奇怪的日期.
谢谢
假设我有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的例子)
我想知道其他人如何处理这个问题?
谢谢