dGohil
dGohil

Reputation: 21

Actual role of WEB-INF in a java web application?

I am creating a web application using Java, Spring, Hibernate and AngularJS. but I am not clearly understand the role of WEB-INF directory. As per I know WEB-INF is a web directory where we keep our web configuration files. But I have seen some example in AngularJS app where js and html are put in WEB-INF folder and it is known that WEB-INF is not publicly accessed. So why do we put those files in WEB-INF and what actually mean of publicly accessed even when we response for a request html and js are visible to clients, and if we put in WEB-INF folder these files how to access those files.

I need some clarification on these few points before starting my app development. Please anyone can help me regarding these issues.

Upvotes: 1

Views: 2086

Answers (4)

Brian Clozel
Brian Clozel

Reputation: 59086

You don't have to use WEB-INF at all. Here's a simple AngularJS example app (official Spring guide) on how to do this.

Now, like Elliot mentions, sometimes using proxies is a good idea (depending on the kind of traffic your application should support). You could also use a CDN, which is easier to set up and has no configuration requirement in your application.

Upvotes: 0

Cuzz
Cuzz

Reputation: 448

In case of Spring you can build your app without WEB-INF directory. For example: spring-boot + thymeleaf, it is possible put all html, css and js files to src/main/resources/static .. so WEB-INF directory is not necessary for all java web applications.

Upvotes: 0

icza
icza

Reputation: 417622

As you said, we put configuration files into the WEB-INF folder. But there are cases when you use resource files (e.g. HTML templates) which are not sent to the client as-is, but usually some transformations or parameter substitution happens, which are usually handled by a Servlet.

It is ok to put such templates and resources to the WEB-INF folder because the files as are should not be visible/accessible to the clients but only the result of transformations/parameter substitutions.

Upvotes: 2

Elliott Frisch
Elliott Frisch

Reputation: 201447

Resource files are frequently stored within WEB-INF because the Java servlet container will not directly serve those files. Instead, some Java controller code is being used to serve them indirectly. This is perfectly acceptable, but I would prefer a solution that serves static content from a different server and let the Java container handle dynamic code only. In a pinch, you might just add a reverse proxy and off-load static content handling that way.

Upvotes: 1

Related Questions