Why does this jquery example of w3s not work within web-inf?

Asked

Viewed 73 times

1

Good guys I have a project in Maven, and in my folder I have this structure

src > main > webapp > WEB-INF > jsp > index> index.jsp, demo_test.txt

This code is inside my web-inf inside my index.jsp the two files are inside the index folder.

when I shoot from WEB-INF and put into webapp it’s right.

  • 1

    Stackoverflow works best when questions are self-contained, without links to external sites: http://answall.com/help/mcve. Also remember to tell us what errors you got. " worked out" and "didn’t work out" aren’t precise terms.

2 answers

1

probably the problem is about the address of the demo_test.txt file, as it is inside a folder, you have to pass its full address, something like:

$("#div1").load("./jsp/index/demo_test.txt");

0

The briefcase WEB-INF is protected by containing the settings, classes and libraries of a Java application. It is not allowed to access any resource from this directory via URL for security reasons.

However, it is possible to make a include within the server itself, that is, a JSP accessed outside the folder WEB-INF can include a JSP from that folder.

It is also possible to forward (forward) one sponse to a JSP within that folder from a Servlet or controller.

And finally, it is possible to read files from that folder using the method ServletContext.getResourceAsStream(). Example:

servletContext.getResourceAsStream("/WEB-INF/jsp/index/index.jsp");

But usually this is done for configuration files or other static files and not for Jsps.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.