Jeef
Jeef

Reputation: 27275

ServletContext.TEMPDIR cannot be resolved or is not a field

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.

Is not tempdir part of the servlet context?

I'm suing JSF and Spring btw.

enter image description here

Upvotes: 0

Views: 742

Answers (1)

BalusC
BalusC

Reputation: 1109072

That constant was introduced in Servlet 3.0, which is part of Java EE 6.

Your problem suggests that you're compiling your code against Servlet 2.5 or older, where this constant was absent.

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.

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"):

File tempdir = new File(System.getProperty("java.io.tmpdir"));

Again another alternative is to make use of File#createTempFile():

File tempfile = File.createTempFile(timeString, ".xlsx");

Upvotes: 1

Related Questions