404 -resource under sub-directory not found in eclipse - eclipse

I am able to access a resource(say test.html) only when it is directly under WebContent in eclipse.If i place it in WEB-INF or WEB-INF/jsp the IDE shows error 404-requested resource is not available.
http://localhost:8080/MyApp/test.html (This works when test.html is under WebContent and not any of it's subdirectory)
When it is in WebContent/WEB-INF
Right click-run takes to the below URL which shows 404-resource not available
http://localhost:8080/MyApp/WEB-INF/test.html
How do i access it by placing "test.html" in WEB-INF or WEB-INF/jsp?
All configurations are default with no restrictions specified in web.xml and using Tomcat 7 as the web server

To prevent access to specific files. You cannot access /WEB-INF/ directory from outside the server itself. If you want to create subdirectory create them under
WebApp/
-index.jsp
-YourSubdirectory/
--test.jsp
test.jsp can be accessed via localhost:8080/MyApp/YourSubdirectory/test.jsp

Files at WEB-INF directory cannot be accessed directly from browser. This is the basic restriction.
However content of this directory could be accessed at application level. Web container provides such opportunity.
For example, if you using SpringMVC, you can map some URL to the file at WIB-INF directory and it will work correctly.

Related

How to include public_html sibling folder in a PhpStorm project?

I have the following site directory structure (on a shared hosting):
/home/username/
public_html/
index.html
resources/
config.php
I am trying to set up a new project using the remote deployment in PhpStorm. I'd like to have both public_html and resources folders accessible, since both contain PHP files. I am confused by what should be the Project Root. Logic suggests that my project root is the top level directory containing all my files, i.e. /home/username/.
However if I mark it such in PhpStorm, the next screen (Specify Web Path) automatically maps my web root folder to the project root.
As the result, if I run /home/username/public_html/index.html from PhpStorm, it tries browsing to https://webroot/public_html/index.html. This is wrong. The web root should be mapped to /home/username/public_html. Actually, the very question ("Web path for project root '/home/username'") is invalid, since there is no web path to folders above public_html, that's the whole point of putting resources there. How should I properly configure folders in PhpStorm?
Such setup is definitely possible -- its very common to have website root folder as a sub-folder of the actual project.
As far as I'm aware it is not possible to create such setup right from New Project Wizard -- it has to be done at later stage when project creation was completed.
You need to go into Settings/Preferences | Build, Execution, Deployment | Deployment and add new mapping. Here is an example:
Here my website root is located in web folder -- you will have to change that to yours public_html. This way when you use Open in Browser on file inside your web root folder it will be opened with correct URL.

How to deploy gwt static pages in jboss

I have some static files ( html, javascript, css - compiled gwt client code). I need to deploy that files in jboss.
That is I need to access like http://localhost:8080/Client/homepage.html .
Where do I need to put the files in jboss.
I tried putting it in
D:\Program Files\jboss-4.2.3.GA\server\default\deploy\Client\homepage.html
restarted the server and tried to access
http://localhost:8080/Client/homepage.html.
But it shows 404 error.
How should I fix this?
If you rename Client folder to Client.war, the example will work.
You don´t need to do anything special to deploy static files, just place them in a valid war and that´s it. By valid war I mean having a WEB-INF folder with your web descriptor inside (web.xml), lib and classes folder, etc..
It is shown here:
http://docs.oracle.com/javaee/5/tutorial/doc/bnadx.html

Problems with relative paths in Eclipse.

I am trying to use relative paths in a Dynamic Web Project in Eclipse. I am NOT using them in the Servlet, but in another class that is called by the Servlet. The file I am trying to access to is a property file located in
MyProject/WebContent/WEB-INF/propertyFile.properties
I have tried almost every relative path...
WebContent/WEB-INF/propertyFile.properties
/WebContent/WEB-INF/propertyFile.properties
./WebContent/WEB-INF/propertyFile.properties
MyProject/WebContent/WEB-INF/propertyFile.properties
/MyProject/WebContent/WEB-INF/propertyFile.properties
WEB-INF/propertyFile.properties
/WEB-INF/propertyFile.properties
./WEB-INF/propertyFile.properties
...and so on...what can I do?
Thanks in advance!
You nee to understand that file IO read files, from the filesystem, and relative to the directory from which the JVM (i.e. your web container) is started.
Remember that, once your app is deployed to production, there won't be any MyProject or WebContent folder. That's what exists on your development machine. The only thing that will exist in production is the war file deployed in the application server.
What you actually want is to load a resource, located in the deployed web application (i.e. which is inside your war file).
To do that, you must use ServletContext.getResourceAsStream():
InputStream in = servletContext.getResourceAsStream("/WEB-INF/propertyFile.properties");

Deploying Java application via Java Web Start(.jnlp), directory permission and location?

In my jnlp file I need to use nativelib tag.
<nativelib href="lib/windows/alib.dll"/>
is that href refer to the directory on my server? what if my jar application looks for the alib.dll inside it's bin folder? how would I indicate this?
will there be any issues with write permission on where the application is installed (where is the default jnlp installation folder and how does the user change this?)

Configuration about eclipse + Tomcat

I wrote a little helloworld jsp file to test it. But it failed. I can't figure it out.Any one help me ?
I got these error info:
HTTP ERROR 404
Problem accessing /myjsp/WEB-INF/myjsptest.jsp. Reason:
NOT_FOUND
HTTP error 404 means that the requested resource was not found by the server.
The problem doesn't seem to be related to Tomcat or Eclipse but rather to your web application. I think the reason is that you are trying to access a JSP file in WEB-INF folder. You shouldn't do that because WEB-INF folder is not accessible directly from a web browser. Your JSP files should be outside of it.
WEB-INF folder is used to store configuration files (e.g. web.xml) and Java classes (e.g. servlets). JSP files and all static content should be placed outside of it.
You may find more information about JSP technology e.g. in this tutorial or this tutorial (in Chapter 12).