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
Related
I have created a java web application and created the file thymeleaf.war to deploy it on a tomcat server.
I access the tomcat manager using www.lux-systems.com/manager/html and have uploaded the thymeleaf.war file on this page.
Now i can see /thymeleaf in the application list, but when i click on that link (www.lux-systems.com/thymeleaf) I only see the directory listing instead of the web-page I want to see.
The problem is that I can't find the url to the working web page, and I am wondering why www.lux-systems.com/thymeleaf is only showing the directory listing.
I am trying to do a little project where I download a file through the browser. I want to use Tomcat for that.
I installed and ran Tomcat, on addresss http://localhost:8080/ I have main Tomcat site. I placed file test.txt into webapps/test/ and I am trying to enter http://localhost:8080/test/test.txt, but it does not work. All I see is Error 404, requested resource is not available. What do I I need to do? Create some application not only directory in webapps? Or should I set some mapping from URL to file?
I've installed Eclipse with web development and during download have installed Tomcat7 to dir E:\Eclipse\tomcat7.
When in Eclipse and trying to test the program I'm getting a realPath of
C:/Users/user/Documents/eclipseJEEWorkspace/javaWebPages/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/org.example.web/WEB-INF/classes/
as my real path and not what I expect which is E:\Eclipse\tomcat7\webapps\org.example.web/WEB-INF/classes/
1) how do I get the real path of the servlet rather than the temporary path...
or am I missing something with how Eclipse uses the installed server? If this is the way then do I have to continuously create the WAR and fiddle around recreating/deleting all the time?
The reason for this is I'm also trying to get a JAVA Servlet getting access to a file in a path higher than webapps. I'm new to servlets....
My development includes third party software that all reference an individual file our.properties so changing the structure is unfortunately not a option.
My directory structure is:
/tomcat
/mycompany
/properties
our.properties //the file we want to access
/*otherfiles
/html
/*not used in this context but to show usage
/javascript
/*not used in this context but to show usage
/webapps
/org.example01.web
/META-INF
/WEB-INF
/org.example02.web
/META-INF
/WEB-INF
/org.example03.web
/META-INF
/WEB-INF
How do I tell my Servlet to access the our.properties file?
I've tried getPath, getResource but without getting the first bit to work, I doubt I'll be getting anywhere fast.
Thanks
When you run Tomcat under Eclipse, via the Tomcat plugin, the webapps path is changed. Eclipse uses .metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ folder to deploy the project. That's not a temporary path, it's the actual path since your web application is deployed there.
If you run tomcat from command line, or as a service and deploy your web application, you'll see that the path of the servlet will be as you expected.
In order the change the default path to deploy for Eclipse, double click to your Tomcat under Servers view and modify Server locations section.
I previously used the following to get my context path on Tomcat-5.0.28 and earlier:
String context_path = context.getRealPath("/WEB-INF/");
This worked to return the path to that folder.
But on OpenShift (Tomcat 6 - JBoss EWS 1.0) this returns
/var/lib/openshift/53.*context_id_here*..18/jbossews/null
The null should be:
work/Catalina/localhost/_/WEB-INF
How can I get the path to the WEB-INF folder on OpenShift using JBOSS/Tomcat?
A little background information: When I ran this struts webapp on my own Tomcat server, I deployed a appname.war file in the webapps directory and waited for it to expand (since I had set that option in the server.xml file). Then I move a folder to webapps/appname/ folder with xml files I need to read and write to for my app to work. On OpenShift I used jar xvf appname.war to extract the war file by hand (because that's the default and I don't know how to change it), and then moved the files folder (from the same directory as the war file in my folder after a git add and push) to work/Catalina/localhost/_/WEB-INF/
This is causing a NullPointerException for me when trying to use that path as shown above.
I think you should be using something like getServletContext or getRealPath, and reading it from the web root instead of trying to find the file on the physical disk. That way your war file can run anywhere without issue. Try looking up both of those and see if one fits your use case.
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).