I have an Eclipse Java project, and I added a "folder" off of the root called "webfiles". I then proceeded to create a file called form.html. Once I run the project locally or publish it, I cannot reach the .html file. I get a Not_Found error.
Is it possible in Google App Engine to use HTML files (other than index.html) and where do I have to place them in the project to access them by a browser? What path should I use in the browser.
You need to add include path="/**.html" " in your static files definition in appengine-web.xml else html files other than index.html would not even be uploaded.
If you have /war/webfiles/form.html in your project than path to acces it from browser:
http://your_app_name.appspot.com/webfiles/form.html
To make reference from other jsp pages use:
link to form
Related
I have a spring boot application that runs very well, But after generating a war file so as I can run the application on separate tomcat server not the embedded one, I am unable to access some pages and files. I have rename the generated war file to mywarfile.war .This qusetion has two separate relate issues.
First issue-Access a linked page
Below is the link inside index.html that will lead to a method that will perform some code then leads to all.html
<button class="btn btn-secondary"> View Welding Product Record </button>
Method
#GetMapping("/all")
public String getAllProducts(Model model){
//.....codes
return "all"
}
Everything works fine with embedded tomcat with spring boot, but when click the link with the war file deployed to separated tomcat server it redirects to http://localhost:8080/all and shows below error.
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/all] is not available
Description The origin server did not find a current representation
for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.65
The mywarfile.war is placed on C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\mywarfile.war
But if I type manual on url http://localhost:8080/mywarfile/all I can access the page. What could be the cause of this. And How can I fix it.
Second issue - Access images
I have a background image in my index.html that can be accessed before generating the war file, But after generating the war file and run it on separate tomcat server I cannot see the image.
Below is the code in index.html
<style>
body{background-image: url('/images/ocean.jpg');}
<style>
This is the structure of how I store the images in my project
\src\main\resources\static\images\ocean.jpg
what could be the cause of this and how can I solve it. Thanks in advance
I am new to Spring framework in spring site There is tutorial at https://spring.io/guides/gs/uploading-files/ that upload file to the root folder "upload-dir" (this folder is beside src root folder)
questions:
How can I access and show image in browser (or access it in thymeleaf by th:src="#{}" syntax) -
by browsing to localhost:8080/files/first.jpg because of controller it give me download link.
should I always upload file to folder that beside src folder for example I want to upload file to "src/main/resources/static/file" is it possible?
When accessing files in your code, Spring will (by default) assume that the src/main/resources is the parent directory. If you are planning on accessing the files that are uploaded, then I would use src/main/resources (or a subdirectory of this location) as the upload path. This way, you can simply access them in Thymeleaf as such:
Location: src/main/resources/picture.jpg
Thymeleaf: th:src="#{picture.jpg}"
Or if the file exists in a subdirectory:
Location: src/main/resources/somedir/picture.jpg
Thymeleaf: th:src="#{somedir/picture.jpg}"
If you are storing the file(s) elsewhere, then you can also access them using various prefixes like classpath or file, i.e.:
classpath:com/myapp/config.xml
See more about Resources in Spring here:
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/resources.html
Hope this helps!
Im trying to read files(xml, images) from src/main/resources. But it doesnt work.My resources folder is Source folder. For example, when i m trying to read log4j.xml tomcat looking for it in C:/bin... And i also cant read images from resources. I can read it only from webapp. I ve read, that tomcat automatically replace files from resources to webinf, but i think that it doesnt work in my case.
Please, help. I dont have any idea.
Even if the png is added to the WEB-INF folder it wouldn't be accessible from the JSP page in your case.
On runtime a JSP page renders into a servlet that return HTML code in the response. Then a browser will parse your tag <img src="/Pajero.png" ... /> and send a request onto YOUR_HOST/Pajero.png url to access the image and get the error code 404, because content of the WEB-INF folder is not accessible for a client side in a java web application.
Perhaps it will be better to place images on the webapp folder at your case.
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("log4j.xml").getFile());
You can use something like this to get resources from classpath.
Regards
I just want to finish a simple HTML 5 example.
<audio src="2.mp3" controls autoplay>
Your browser does not support the audio element.
</audio>
but it can't complete and this is the description from Tomcat:
"The requested resource (/DemoPlaying/2.mp3) is not available."
My folder structure:
It's obvious that your mp3 file is not available at the URL you're trying to request it. Correct your 'src' to point to the correct url.
I think you must remember:
1) If your app is wellformed, then the typical structure is like:
http://myserver:8080/myapp
2) Then your file must be published under the contexto of your app
http://myserver:8080/myapp/mp3file
3) So, in development time your structure must be:
Webcontent
|
|--index.jsp
|--mymp3.mp3
|--WEB-INF
4) And war file must content the same of Webcontent (or root folder of your app)
Only in that way your file will be detectable by the server, and dont forget to registrer the extension on Tomcat Server
Where to put files in a Tomcat Servlet application, such that they are relatively visible to the page??
More detail:
I am developing a servlet page while using an external library. That library depends massively on external loaded XML files (relative file paths). So I need to put these XML files in the running directory of the servlet.
Is there a way in Tomcat server, where files can be accessible relatively?
When a web application is deployed to Tomcat, the root of the web application ends up being $CATALINA_HOME/webapps/YOUR_WEB_APP/
As such, if using a servlet to access an XML file located on a path within the root of your web application, you can just use the following:
request.getServletContext().getResourceAsStream("PATH/TO/YOUR/XML_FILE.xml")
This will load the XML file as an InputStream. Of course, if you want access to the file itself, you can always use the getResource(String resource) method to obtain a URL, from which a File object can be obtained like so (alternative methods included):
File f;
try {
f = new File(url.toURI());
} catch(URISyntaxException e) {
f = new File(url.getPath());
}
EDIT: To make them relatively visible to a web browser, simply keep them out of the ./WEB-INF and ./META-INF directories.
If this library you are talking about is going to search for the file on the classpath (like Hibernate or Log4J would do), you will have to put your XML file in WEB-INF. However, I suggest you do not do this manually. You can put the file in a source directory of you application, which will make sure the file gets deployed on the right spot.
This is an old question. I'm working on Tomcat 9. I've been quite successful with taking the Tomcat installation directory as the base. (CATALINA_HOME) The relative path to a file in ROOT for example is then, "webapps/ROOT/someDir/fileName"
The place to complain about repeated answers is to deal with repeated questions.