I deployed my ROOT.war to Tomcat webapps folder. When I'm writing in a web browser address www.exampleaddress.com I can see index.jsp file.
But in the same folder is file.js. I Would like to see it when I write address: www.exampleaddress.com/file.js but now i can see only empty white page without any code. Any ideas?
You can't place JS files or any publicly accessible data inside the WEB-INF folder. You need a JS folder in the same directory as your WEB-INF folder and that is where you place them. The same goes for your .css files and your images. None of that can be seen from inside WEB-INF.
/WebApp/CSS/index.css
/WebApp/JS/index.js
/WebApp/WEB-INF/index.jsp
/WebApp/Images/logo.png
Related
I am deploying a war to a tomcat web server. (struts 1, not 2)
It needs to display a link for the user to download a static document that is to be included in the exported war.
What folder inside the deployment war should I store the document in, and how should the url link to the file?
http://localhost:8080/SampleWar/sample.html
consider sample.html file in webapp folder
your file should be inside webapp , but this way anyone can access no security , for example you can also have sample.txt or etc
I have a folder called attachments in my webapps folder in my Apache Tomcat directory, in which I need to save some files and images. When I'm giving the local path i.e. in C:/ the files needed are being saved in the correct location.
However I need to load these images from the server at runtime so I'm trying to access the image by the localhost url /attachments/img.png. The image is not being found (404 error).
I tried opening Tomcat's manager to see if attachments is listed. It is there however when I click it a 404 error is being thrown too. Other deployed web applications are being found.
What could be the cause of this?
You cannot just create a folder in $CATALINA_HOME/webapps like this and access it from web browser.
webapps folder is supposed to be home for all web applications with proper J2EE web app like directory structure e.g. WEB-INF/web.xml, WEB-INF/classes, WEB-INF/lib, META-INF etc.
Read more about Web Application Directory Stricture
I am working on a dynamic web project in Eclipse with Tomcat 7. All of my html, css and javascript files are inside the WebContent folder in the eclipse workspace. All the java files are inside the src folder. All works well for simple programs. But now I want to read a text file from the java programs. I am not sure where to put the text file in the eclipse workspace so that it is correctly deployed to the Tomcat webapps directory inside ./metadata folder of eclipse.
You can use the ServletContext.getResourceAsStream() API.
An example can be found at this link . It suggests that the file should be kept in the /WEB-INF directory
put ur files inside webroot folder or outside webroot folder any where it is possible to read files .
inside classes folder is good because of default classpath for webapplication
i'm new to java and have a strange problem.
i create some folder(theme, js, css) in WEB-INF folder and put my files to this folders.
in index.jsp i use a css file by following way:
<style type="text/css">
<%#include file="WEB-INF/css/style.css" %>
</style>
it works good.
but in style.css file i have a div tag that set a background for header tag by following way:
#header{
background: url(../theme/violet/header.jpg) repeat-x;
}
oh. my problem is here. it doesn't work. since other css command work very good.
i know that WEB-INF detail aren't accessible but may there is a way like the way that i use for link style.css in my index.jsp page.
any solution?
thanks.
From the way you include style.css, I guess your index.jsp is outside the WEB-INF folder which can be accessed directly by client browser. The reason the included style.css works fine is because it is included on the server-side. But in the style.css, to get the background image, the browser will launch a new connect to the image which happens to be inside the WEB-INF folder and the server refuse to send it back and you are doomed.
If you have a centralized controller servlet, you can put your jsps inside the WEB-INF folder to prevent it from accessed directly. Your servlet will redirect all request to appropriate jsp according to request parameters.
As far as I can tell, there is no absolute reason to put images, JavaScripts etc inside this folder, you will definitely run into problems when the browser need to access this folder to retrieve data.
That is not possible. If you want content directly accessible from a browser it can not reside inside WEB-INF.
Why you create theme, js, css in WEB-INF Folder? WEB-INF directory contains metadata about the application. During normal operations, you should not need to modify anything under the WEB-INF directory.
you can create theme, js, css folder under war or WebContent directory directly it will easy to use in your jsp pages.
this link will help you.
I want to download an image file using a javascript client. Then I want to call the servlet in apache tomcat from the applet.
How do I host the file on tomcat. i.e. the same as hosting it in the 'docroot' folder on regular webserver?
Just drop the file in a subfolder of the /webapps folder. E.g. Tomcat/webapps/images/foo.png. It'll be available by http://localhost:8080/image/foo.png. Or if you already have a webapp, just drop it in the web folder (there where you also put your JSP files and where the /WEB-INF folder is also present).