I've deployed Test.war file on Openshift and my application test-sliwa.rhcloud.com/Test run OK. When I deploy ROOT.file application test-sliwa.rhcloud.com doesn't run in right way - first page is ok, but when I try to link to other pages I have 404 error.
The problem was in source code in links declared. It's better to declare domain-relative URL like:
<a href="<%= response.encodeUrl(request.getContextPath() + "/Controller?action=login") %>">
instead of:
<a href="Test/Controller?action=login")">}
in index.jsp file.
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'm having a problem when deploying a Spring Boot application as a WAR file to a standalone Tomcat 7 server. It builds and deploys fine but when the index.html page tries to load other static resources they are missing the context in the url so fail to load (404).
e.g. http://localhost:8080/app/images/springboot.png
should be: http://localhost:8080/spring-boot-war-context-issue/app/images/springboot.png
Image showing issue
It works fine when using the embedded Tomcat
Similar issues:
Seems to be a similar issue to:
Spring-Boot war external Tomcat context path
However the suggestions in that question did not seem to solve my issue. I wasn't sure about the Tomcat xml file.
Steps followed:
I created a simple sample application and followed the steps in the Spring Boot docs.
The sample code can be seen in this github repo along with steps to reproduce the problem: https://github.com/jgraham0325/spring-boot-war-context-issue
Things I've tried so far:
Set contextPath in application.properties but this only applies to embedded tomcat
Tried using a fresh install of Tomcat 7
Tried creating a config file in tomcat to force context:
apache-tomcat-7.0.72\conf\Catalina\localhost\spring-boot-war-context-issue.xml
Contents of spring-boot-war-context-issue.xml:
<Context
docBase="spring-boot-war-context-issue"
path="spring-boot-war-context-issue"
reloadable="true"
/>
Any advice would be much appreciated!
Thanks
Update 23/10/2016:
Alex's answer below about using relative URLs without the slash at the start was perfect solution!
Isn't it simply caused by the way you defined your url in index.html (the url does not include the context root):
<img src="/app/images/springboot.png" />
Use relative uri
You should be able to use a relative uri (without the leading forward slash):
<img src="app/images/springboot.png" />
get the context root
How do you get the contextPath from JavaScript, the right way?
How to set ContextPath for an image link
Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP
How to use relative paths without including the context root name?
With JSP/JSTL:
<img src="${pageContext.request.contextPath}/app/images/springboot.png" />
Or with Javascript:
function getContextPath() {
return window.location.pathname.substring(0, window.location.pathname.indexOf("/",2));
}
...
var img = new Image();
img.src = getContextPath() + "/app/images/springboot.png";
document.getElementById('div').appendChild(img);
If using Thymeleaf, another way is using Context-Relative URLs like below:
<link rel="icon" type="image" th:href="#{/img/favicon.ico}"/>
For more information please refer to: Thymeleaf Documentation
I have a file hello.jsp. Its working fine in tomcat when I type localhost:8080/hello.jsp in the url tab of the browser.
However when I try to call the file from html like this:
<form action="hello.jsp">
I get the error
"Your file was not found ,It may have been moved or deleted"
and no page is loaded. How can I run my file through HTML page. I am having same problem with servlet too.
I m new in Struts2. Creating a hello world program using struts. When I run it got first screen where i put my input but when click on submit button giving following error.
Source of this helloworld example: http://www.tutorialspoint.com/struts_2/index.htm
HTTP Status 404 - /HelloWorldStruts2/hello
type Status report
message /HelloWorldStruts2/hello
description The requested resource (/HelloWorldStruts2/hello) is not available.
Apache Tomcat/6.0.29
Suggest what is the issue?
Got the solution.
In index.jsp there was <form> tag. When I changed it to <s:form> its working fine.
Or change from
<form action="hello">
to
<form action="hello.action">
This is what worked for me, specific to the question. Tomcat 8 was used:
Make sure you have created the classes folder under WebContent\WEB-INF.
In that create the logging.properties file and add the following content to it. (It doesn't matter if the file jumps on its own to Java Resources > Libraries) :-
org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = \ java.util.logging.ConsoleHandler
Then in the location of Tomcat's webapps folder delete your HelloWorldStruts2.war file.
Now follow the site's instructions to Export your project to a new HelloWorldStruts2.war file (remember to overwrite the existing .war file with the same name if it's there).
Again, deploy this file by copying it to your Tomcat directory's webapps folder.
In the browser, go to http://localhost:8080/HelloWorldStruts2/index.jsp again, though I'm not sure it will work for sure this time.
But this time, watch the Tomcat server application's verbose output. You will get some kind of exception like this (leave out Warnings for now):
30-Mar-2014 17:39:29.273 SEVERE [localhost-startStop-7] org.apache.catalina.core.StandardContext.filterStart Exception starting filter struts2 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:213)
at org.apache.struts2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:102)
...
Seeing this, what I did immediately was copy the commons-lang3-x.y.z.jar to the WebContent\WEB-INF\lib folder, and then exported and deployed the project again.
This time, again the page wasn't showing, so I watched the logs and found out that Tomcat did not explicitly clear the contents of the webapps\HelloWorldStruts2 folder.
After deleting both HelloWorldStruts2 and HelloWorldStruts2.war and refreshing the index.jsp page in the browser, my project did work fine!
After moving my web project from Tomcat / directory to subfolder /WebApp I get an error GET http://localhost:8080/partials/view-worker-apps-used.html 404 (Not Found)
This is my project structure:
- WebApp
- partials
- view-worker-details.html
- view-worker-apps-used.html
- js
- controlers.js
- services.js
- index.html
First I load http://localhost:8080/WebApp/#/screen2
which is view-worker-details.html injected into index.html by $routeProvider
In loaded view-worker-details.html screen there is
<div ng-include="/partials/view-worker-apps-used.html"></div>
I prefer to not put WebApp prefix into path of ng-include.
How I can fix this problem?
You can take one of following approach.
Approach 1: If you are sure that your contextpath will not change then use following path in ng-include.
<div>
<div ng-include="/WebApp/#/screen2/partials/view-worker-apps-used.html"> </div>
</div>
Note: Remove single quote; it's not require so remove it to avoid confusion
Approach 2: If you think that your context name may change in future then I will suggest to re verify the location of following files.
a. First try by removing extra single quote
b. Verify the location of view-worker-apps-used.html file using following URL
/WebApp/#/screen2/partials/view-worker-apps-used.html
c. Verify the location of file in which you have added following line of code and make sure that relative path you have used as "partials/view-worker-apps-used.html" is valid.
<div>
<div ng-include="'partials/view-worker-apps-used.html'"> </div>
</div>
I hope it may help.