How do I display an HTML file using Websphere Liberty? - html

I have static HTML pages. Using the Apache server (through XAMPP) I used to put my HTML files in the htdocs folder and they would be accessible through the localhost URL.
I'm not sure how to do this with Websphere Liberty server. let's say I have the following HellWorld HTML example in index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HellWorld</title>
</head>
<body>
<p>HellWorld</p>
</body>
</html>
How can I get this HTML page to show in the browser through Liberty?

The minimum folder structure needed is the following
+ SampleHTMLSite.war
- index.html
To create the .war file just zip your index.html file and then change the extention of the zipped folder from .zip to .war
If you are running Liberty sever in foreground through server run command, as soon as you put this website in Liberty's dropins folder (usually located here: ...\wlp\usr\servers\YourServerName\dropins) you will get something like the following update:
[AUDIT ] CWWKT0016I: Web application available (default_host):
http://localhost:9080/SampleHTMLSite/
[AUDIT ] CWWKZ0001I: Application SampleHTMLSite started in 0.317 seconds.
If you go to http://localhost:9080/SampleHTMLSite/index.html you should be able to see your HelloWorld HTML page.
If you get the following error:
Error 404: java.io.FileNotFoundException: SRVE0190E: File not found: /index.html
Open your SampleHTMLSite.war with any unzipping program (example: 7-Zip) and be sure that the index.html is showing directly inside the .war file and not inside another folder. There is a chance that you have the following structure:
+ SampleHTMLSite.war
+ SampleHTMLSite
- index.html
This would mean to access the index.html you need the following URL:
http://localhost:9080/SampleHTMLSite/SampleHTMLSite/index.html
In bigger project and where you need to use Java apps your folder structure might need to include other folders and files. If you are intrested to know more about this, check the following article:
Handling Static Content in WebSphere Application Server

The simplest:
In dropins folder (\wlp\usr\servers\serverName\dropins), create folder myApp.war
put your index.html in the myApp.war
If your server is configured for polled monitoring you are done. Otherwise restart the server (if was started).
It will be available via http://host:port/myApp/index.html.

Related

Index.html without XAMPP

Is it possible to automatically load index.html on a system folder without using XAMPP, IIS or similar?
It is for a school project and I can't use them, so I have to open the file putting the path (C:/...) into the address bar.
I know I could use .htaccess, but I don't know what to write and if it gets read without any web server solutions!
This can get a little tricky... but is possible without any "administrator" privileges, nor without installing anything.
Download Python 3.8.2 - Windows x86-64 embeddable zip file
Create a folder on "python" on the c:\
Extract the "Zip" file into this folder
Change the folder name from "python-3.8.2-embed-amd64" to "python_src"
Create a folder named "python_html"
The folder structure should look like:
c:\python\
c:\python\python_src\
c:\python\python_html\
Create a file named "webserver.py" in the "c:\python\python_html" folder
Place the following code into that file:
#webserver.py
import http.server
import socketserver
PORT = 80
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
Save and close the file
Create index.html file in the "python_html" folder and place the following code in that file:
<html>
<head>
<title>Web Title</title>
</head>
<body>
<h1>Python Web Server File</h1>
<p>Congratulations! The HTTP Server is working!</p>
</body>
</html>
Open the "Command Prompt" and type the following commands
cd\
cd python\python_html\
c:\python\python_src\python ./webserver.py
Open a web browser and navigate to "http://localhost/"
Once you have confirmed this works, you can build an entire website within that "python_html" folder. As long as you don't close the command prompt it will continue acting as a "Web Server".
I know I could use .htaccess
.htaccess is an Apache (Web Server) config file, so unless you have Apache installed (ie. the "A" in XAMPP) then you can't use that. (If .htaccess was available then index.html would likely load automatically anyway.)
On Apache, being able to load index.html by default when requesting a directory requires mod_dir (an Apache module). In this case, mod_dir issues an internal subrequest for the DirectoryIndex - this all requires additional processes.
I can't install extensions... I have to open the file on my school computer
If you can't install anything then you can't do this I'm afraid. You appear to be limited to direct file requests.
When using a webserver (such as Apache or IIS) then you have a differentiation between a URL and a filesystem path. The webserver maps the URL to a filesystem path. Without a webserver you don't have that abstraction.
There are lighter webservers, other than Apache and IIS, but you need to install something extra.
Just give your file(s) meaningful names (ie. not index.html) and use those instead? eg. fox-project.html

Downloading file from ubuntu server through html

I have my domain pointing at a ubuntu server hosted by amazon ws, and I have my index.html file that gets loaded when someone makes a request to my domain, in the same folder of that index.html file I have another file, and I would like to make it possible to download it from my website. How can I achieve that? I tried with an iframe tag, and giving it src="./myfile.jpg" but the server tries to look for it at www.mydomain.com/myfile.jpg and it can't find it there. Can anyone give me any suggestions?
Btw my files are inside /var/www/html folder, which from what I understood is the default folder for public files on ubuntu.

Linux - Difference between transferring files and creating them - Permissions

I am running an Apache web server on a machine running Centos.
THE PROBLEM:
When I run the server, everything works fine and I can see the welcome page. The problem occurs when I try to put in an index.html file I previously created into the /var/www/html directory. When I do this I get the error: Forbidden you do not have permission to access index.html on this server. The weird part is I created an index.html file as root in this directory and it works. It was just a simple test html file:
<!DOCTYPE html>
<html>
<head>
<h1>Hello World</h1>
</head>
</html>
This works. So I tried copying the html text from the original index.html to the one I specifically created in the /var/www/html directory and that works. The only problem here is now I have to create lots of new files in the html folder and copy the contents of the old files into the new ones. Also, how would I get images to work? And Hence, my question. So what is the difference between moving files to a directory and creating them there?
Note
I know I have set the server up correctly because I am able to access it from another computer so I don't think there is an error with the httpd.conf file. Also, I am not using a .htaccess file. The permissions on each file is the same, only one works and one doesn't. The permissions I have tried are -rwxr--r-- and -rwxrw-rw- and -rwxr-xr-x. I have also changed the owner of the files to be the same. I have tried changing the owner to apache and to root. No luck.
Thanks for the help
Moving files retains the SELinux file context assigned to the file when it was created in its original location. Copying it recreates the file anew in the new location, giving it the appropriate file context for that location.
The appropriate file context can be restored on a directory and all files contained within by running restorecon against it. See the restorecon(8) man page for details.

404 page not found - Go rendering css file

I'm currently working in Go. I created a web server on my local machine. I followed the instruction on this page Rendering CSS in a Go Web Application
but I'm still getting the 404 error that the program can't seem to find where my css file is. My directory is as follows.
In src folder contains css/somefilename.css, src also contains server/server.go.
The code inside my server.go file is as follows.
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
When I go to localhost:8080/css/ I get 404 page not found. I'm also using templates to render the html code. The templates are in the folder
src/templates/layout.html
the html code is as follows:
<link rel="stylesheet" type="text/css" href="../css/css490.css" />
Since you don't specify full path for the css folder just a relative one, whether your css files are found depends on the folder you run your application from (the working directory, this is what relative paths are resolved to).
For example if you start your application from your src with go run server/server.go it will work. If you start it from your src/server folder with go run server.go, it will not work. Also if you create a native executable from your app which is put into the bin folder and you start that from the bin folder, this also won't work because the css folder is not in the bin folder.
Either start it with go run server/server.go from the src folder, or copy the css folder to your bin folder and start the executable from the bin folder and it should work (but in this case you also have to copy other static files like html templates).

Running JSP files with tomcat 7

Hi I just installed Apache Tomcat 7 and got the server running OK. When I entered localhost:8089 (8089 being the port I assigned to Tomcat 7) the apache website popped up and I got to run some jsp examples and they opened correctly.
However now I wish to create a jsp file myself (I am trying tutorials for the very first time) and when I open them, only the source code I written is showing in the browser.
The example I am trying is this:
<html>
<head>
</head>
<body>
Hello World. <%= new java.util.Date() %>
</body>
</html>
and all I'm seeing in Chrome is : "Hello World. <%= new java.util.Date() %>"
I am saving this file in this path:
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\host-manager\WEB-INF\jsp
In WEB-INF there is an index.html file ready.
Am I doing something wrong? Where am I supposed to save my file?
I tried watching tutorials on youtube but most of them were in arabic and I couldn't understand a thing!
Thanks in advance for any help!
Your JSP file must NOT be in WEB-INF.
You must create a directory named as you want (myFirstWebApp for example), put your JSP in any subdirectory you want except WEB-INF (for example myFirstWebApp/foo/bar/hello.jsp), then deploy the webapp by copying the myFirstWebApp firectory to the webapps directory of Tomcat. The JSP will then be accessible using the URL
http://localhost:8089/myFirstWebApp/foo/bar/hello.jsp
WEB-INF is where you put the files that you don't want to make accessible from the outside:
the jars (under WEB-INF/lib),
the classes (under WEB-INF/classes),
the deployment descriptor (web.xml, optional in servlet 3.0 webapps configured through annotations),
and any other file you want anywhere under WEB-INF (typically, configuration files).
Why don't you read the documentation? http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html
Rename your jsp-file to:
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\index.jsp
now, navigate to
http://localhost:8089/
Short and Easy.
Put your jsp file in ROOT folder as
/Users/<username>/Desktop/tomcat/webapps/ROOT/test.jsp
Run your application like
http://localhost:8080/test.jsp
Save your jsp file in your webapps directory with .jsp extention
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps
and types at the address bar of the browser- http:\localhost:8089/exmp.jsp
and press Enter key