Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Tomcat:The requested resource () is not available (while acessing the resource that should be avaliable)

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!!

like image 697
MoD Avatar asked Mar 01 '12 13:03

MoD


People also ask

How do I fix HTTP Status 404 not found in Tomcat?

The URL is not handled by any Java servlets If the request URL is /view_books the server will raise HTTP 404 error. You can fix by either correcting the URL or correcting the URL mapping in the @WebServlet annotation.

How do you fix HTTP Error 404 the requested resource is not found?

The simplest and easiest way to fix your 404 error code is to redirect the page to another one. You can perform this task using a 301 redirect. What's 301, you may ask? It's a redirect response code that signals a browser that the content has been transferred to another URL.


1 Answers

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

like image 83
t0r0X Avatar answered Sep 20 '22 17:09

t0r0X