I'm working on migrating some JSF code from one project to another and suddenly in my new project the ServletContext.TEMPDIR
value is failing. I've run through most of my files but this is the only error and I'm not sure where to fix this.
我正在努力将一些JSF代码从一个项目迁移到另一个项目,并且突然在我的新项目中ServletContext.TEMPDIR值失败。我已经浏览了大部分文件,但这是唯一的错误,我不知道在哪里解决这个问题。
Is not tempdir
part of the servlet context?
不是tempdir是servlet上下文的一部分吗?
I'm suing JSF and Spring btw.
我正在起诉JSF和Spring btw。
1 个解决方案
#1
That constant was introduced in Servlet 3.0, which is part of Java EE 6.
该常量是在Servlet 3.0中引入的,它是Java EE 6的一部分。
Your problem suggests that you're compiling your code against Servlet 2.5 or older, where this constant was absent.
您的问题表明您正在针对Servlet 2.5或更早版本编译代码,而这些常量不存在。
Align out the compile/build with the target runtime and make sure that you don't have any servletcontainer-specific libraries in webapp's /WEB-INF/lib
.
将编译/构建与目标运行时对齐,并确保在webapp的/ WEB-INF / lib中没有任何特定于servletcontainer的库。
Or, if you actually need to downgrade from Servlet 3.0 to Servlet 2.5, then replace that constant with the result of System.getProperty("java.io.tmpdir")
:
或者,如果您确实需要从Servlet 3.0降级到Servlet 2.5,则将该常量替换为System.getProperty(“java.io.tmpdir”)的结果:
File tempdir = new File(System.getProperty("java.io.tmpdir"));
Again another alternative is to make use of File#createTempFile()
:
另一个替代方法是使用File#createTempFile():
File tempfile = File.createTempFile(timeString, ".xlsx");
#1
That constant was introduced in Servlet 3.0, which is part of Java EE 6.
该常量是在Servlet 3.0中引入的,它是Java EE 6的一部分。
Your problem suggests that you're compiling your code against Servlet 2.5 or older, where this constant was absent.
您的问题表明您正在针对Servlet 2.5或更早版本编译代码,而这些常量不存在。
Align out the compile/build with the target runtime and make sure that you don't have any servletcontainer-specific libraries in webapp's /WEB-INF/lib
.
将编译/构建与目标运行时对齐,并确保在webapp的/ WEB-INF / lib中没有任何特定于servletcontainer的库。
Or, if you actually need to downgrade from Servlet 3.0 to Servlet 2.5, then replace that constant with the result of System.getProperty("java.io.tmpdir")
:
或者,如果您确实需要从Servlet 3.0降级到Servlet 2.5,则将该常量替换为System.getProperty(“java.io.tmpdir”)的结果:
File tempdir = new File(System.getProperty("java.io.tmpdir"));
Again another alternative is to make use of File#createTempFile()
:
另一个替代方法是使用File#createTempFile():
File tempfile = File.createTempFile(timeString, ".xlsx");