AppEngine, how to use static html files - java

Please, help me, how I can use html files in my appengine application for Java environment (Java SDK)?
When I open it in my browser I got error: HTTP ERROR 404
Problem accessing /myapp/. Reason: NOT_FOUND

I think it depends on what you intend to do :
If you want to serve a static page inside your app :
import (or create) the html page in the folder : YourProject/war
Then you can call it with a relative link in your application:
<a href = 'MyPage.html'> My link </a>
If you want to start the app with a static page, then you must declare it in : YourPRoject/war/WEB-INF/web.xml file, by adding somthing like this this :
<welcome-file-list>
<welcome-file>sign.html</welcome-file>
</welcome-file-list>
I hope it helps !

Have you had a look through the Getting Started documentation?

I added the following to the app.yaml file and it worked for me. This declaration needs to be made right after app_version. Please note that I have placed my html files in the main directory itself.
handlers:
- url: /(.*\.html)
static_files: \1
upload: (.*html)

Related

Spring boot WAR deployed to Tomcat and missing context for static resources

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

Intellij IDE JSP path resolving [duplicate]

This question already has an answer here:
How specify path to .JSP file for request.getRequestDispatcher()?
(1 answer)
Closed 6 years ago.
I have a servelet called RegisterUser mapped as /register this servelet includes a jsp file called register.jsp . here is the structure of the project :
inside the servelet this code cannot find the jsp file :
RequestDispatcher view = request.getRequestDispatcher(registerView);
and the content of registerView is :
private static final String registerView = "../web/WEB-INF/views/Register.jsp";
It worked fine on eclipse but when I switched to Intellij it shows that the file cannot be found .
Liferay has a somewhat strange layout for it's web-inf and html folders. In Eclipse I never really code path completion to work well in JSPs because it always looked at the wrong spot for files. In IntelliJ I just setup different facets that will help the IDE help me. Here is an example. I have a facet called WEB-INF. In Liferay, when you reference a file in WEB-INF (tagfiles are a GREAT example here) you do it like this:
<%# taglib prefix="showMore" tagdir="/WEB-INF/tags/wj/showmore" %>
The problem there is that by default, the IDE wants to autocomplete like this:
<%# taglib prefix="showMore" tagdir="/docroot/WEB-INF/tags/wj/showmore" %>
I simply made a web facet and said that when I type /WEB-INF I really want you to look at /docroot/WEB-INF. This small change saves me so much headache throughout the day. I also did the same thing with /html instead of /docroot/html.
You know how in eclipse when you go to an init.jsp file in the ext environment it always freaks about the init.jsp includes from portal because it can't find it? I once again used a web facet (called portal-web) and I linked / to /liferay/builds/4.3.x/portal-web/docroot. Now when I say:
<%# include file="/
right there it starts autocompleting. It lists out everything in both portal-web and ext-web for me, because I have access to both inside Liferay! Doing this then:
<%# include file="/html/common/init.jsp" %>
it's a problem, I can even click init.jsp and press ctrl (cmd) + b and it will jump me right into the init file in portal.
I tend to run IntelliJ with one "Module" and two "Content Roots". One content root is portal, the other is ext. The plus here is that the debugger knows about the portal source files, and I can easily jump between jsp files as well.
Resource Link:
Why I use IntelliJ instead of Eclipse?

Getting error running struts2 helloworld program

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!

Web Server AngularJs GET 404 not found

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.

Cannot Reach Html File on Google App Engine

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

Categories

Resources