Reputation: 274
This is my first question here (so be gentle :)). I've looked everywhere and cant find the answer to my problem (also went a little crazy in the process).
I'm using Tomcat 7 and latest Eclipse IDE for Java EE developers (Eclipse platform 3.7.2 and Java EE IDE 1.4.2). So, I get this error: "The requested resource () is not available" while accessing http://127.0.0.1:8080/myTest/WEB-INF/jsp/savename.jsp. I've checked many many times that this file is on the disk in exact folder. I've tried running Tomcat inside Eclipse and deploying exported .war in Tomcat. Every time the same error pops up.
My files:
myTest/index.jsp
myTest/WEB-INF/html/GetName.html
myTest/WEB-INF/jsp/savename.jsp
When I run "http://localhost/myTest" index.jsp always runs properly. Then I use
"<jsp:forward page="WEB-INF/html/GetName.html"></jsp:forward>"
inside my index.jsp to navigate to GetName.html and that also works. The problem pops up in GetName.html:
<form action='WEB-INF/jsp/savename.jsp' method="post" >
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20>
<P><INPUT TYPE=SUBMIT>
</form>
When i press submit button in the form, the browser redirects to: http://127.0.0.1:8080/myTest/WEB-INF/jsp/savename.jsp and the error pops up.
So I really don't understand why this is happening... Default Tomcat apps work perfectly...
P.S. I have tried also manualy navigating to files:
http://127.0.0.1:8080/myTest/WEB-INF/html/GetName.html
http://127.0.0.1:8080/myTest/WEB-INF/jsp/savename.jsp
but I also get the error (even when idex.jsp also navigates to GetName.html without any problems)..
Any help is much apreciated! Thanks!!
Upvotes: 6
Views: 9351
Reputation: 4772
You can't directly navigate to any files/artifacts placed under WEB-INF directory (also valid for META-INF). This is a security feature of the servlet engine: content under WEB-INF is protected and not accessible from "outside" via URLs. Else, anybody could read sensitive details like application/database configuration, etc. by just assembling appropriate URLs.
The reason why the "jsp:forward" tag is still able to access files in/under WEB-INF directory is that the forward performs internally on the server, i.e. the request has already arrived to the servlet engine and index.jsp is executed, therefore the servlet engine has fulfilled it's security duties and now the author of e.g. index.jsp is responsible to decide which files have to be accessed.
PS
Besides using "jsp:forward" tags, you can use the include directive (static include), e.g.
<%@ include file=”/WEB-INF/dir/file.extension” %>
or the include JSP tag (dynamic include), e.g.
<jsp:include page=”/WEB-INF/dir/file.extension” />
The differences between these two include types can be googled, good results would be e.g.
http://java.sun.com/products/jsp/tags/11/syntaxref117.html
http://java.sun.com/products/jsp/tags/11/syntaxref1112.html
http://www.coderanch.com/how-to/java/IncludesActionDirective
http://docs.oracle.com/cd/B14099_17/web.1012/b14014/keydev.htm#i1005631
Upvotes: 4