Home > Java > javaTutorial > body text

How to Access Resources in the WAR/WEB-INF Folder in an App Engine Project?

Patricia Arquette
Release: 2024-11-13 16:20:02
Original
765 people have browsed it

How to Access Resources in the WAR/WEB-INF Folder in an App Engine Project?

Accessing Resources in WAR/WEB-INF Folder

Accessing files within the war/WEB-INF folder in an app engine project can be achieved using the File() class. Here's how to construct the required path:

Java code:

import javax.servlet.ServletContext;

ServletContext context = getContext();
String fullPath = context.getRealPath("/WEB-INF/test/foo.txt");
Copy after login

The above code utilizes the getRealPath() method of the ServletContext to obtain the full system path to the resource. Alternatively, you can use the following code if the servlet container doesn't expand the WAR file:

Java code:

import javax.servlet.ServletContext;

ServletContext context = getContext();
URL resourceUrl = context.getResource("/WEB-INF/test/foo.txt");
Copy after login

Note that, alternatively, you can directly obtain the input stream using the getResourceAsStream() method:

import javax.servlet.ServletContext;

ServletContext context = getContext();
InputStream resourceContent = context.getResourceAsStream("/WEB-INF/test/foo.txt");
Copy after login

Regardless of the servlet container or deployment location, the latter approach will always succeed. On the other hand, the former approach requires the WAR file to be unzipped prior to deployment.

The above is the detailed content of How to Access Resources in the WAR/WEB-INF Folder in an App Engine Project?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template