Running JSP files with tomcat 7 - html

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

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.

Copy website folder and contents to Apache web server

I just started setting up Apache web server to try and test a website I am building. After installing LAMP (I'm on Ubuntu 16.04, if that's important), I copied a folder of HTML and CSS code that I had to test. Here is the folder's contents:
Main folder: testsite
Subfolders: articles, images, CSS, HTML, scripts
Contents:
articles -> .docx files
images -> .png files
CSS -> .css files
HTML -> .html files
scripts -> .py files, but one .html file too
When I went to test the Apache web server, it gave a 404 not found. I'm absolutely clueless as to what could be the answer. I tried renaming the maincode.html file that I had to index.html and putting it in the testsite folder, but it didn't change anything. Is there anything I need to do to fix this?
Here's a screenshot of the 404 Not Found page, with the Developer Console open (in Chrome)
I'm not sure what other information I need to provide, but I'll gladly give any info you need.
Make sure your testsite's conf file has the DocumentRoot property set to the path to your testsite folder. The conf file is probably /etc/apache2/sites-enabled/000-default.conf.

How do I display an HTML file using Websphere Liberty?

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.

Deploying just HTML, CSS webpage to Tomcat

I am just getting started on developing a website. All I have at the moment is a HTML page supported by a couple of CSS stylesheets.
Can I create a WAR file from the HTML and CSS pages? How do I deploy them on to a Tomcat server?
Thanks.
There is no real need to create a war to run it from Tomcat. You can follow these steps
Create a folder in webapps folder e.g. MyApp
Put your html and css in that folder and name the html file, which you want to be the starting page for your application, index.html
Start tomcat and point your browser to url "http://localhost:8080/MyApp". Your index.html page will pop up in the browser
Here's my setup: I am on Ubuntu 9.10.
Now, Here's what I did.
Create a folder named "tomcat6-myapp" in /usr/share.
Create a folder "myapp" under /usr/share/tomcat6-myapp.
Copy the HTML file (that I need to deploy) to /usr/share/tomcat6-myapp/myapp. It must be named index.html.
Go to /etc/tomcat6/Catalina/localhost.
Create an xml file "myapp.xml" (i guess it must have the same name as the name of the folder in step 2) inside /etc/tomcat6/Catalina/localhost with the following contents.
< Context path="/myapp" docBase="/usr/share/tomcat6-myapp/myapp" />
This xml is called the 'Deployment Descriptor' which Tomcat reads and automatically deploys your app named "myapp".
Now go to http://localhost:8080/myapp in your browser - the index.html gets picked up by tomcat and is shown.
I hope this helps!
Here's my step in Ubuntu 16.04 and Tomcat 8.
Copy folder /var/lib/tomcat8/webapps/ROOT to your folder.
cp -r /var/lib/tomcat8/webapps/ROOT /var/lib/tomcat8/webapps/{yourfolder}
Add your html, css, js, to your folder.
Open "http://localhost:8080/{yourfolder}" in browser
Notes:
If you using chrome web browser and did wrong folder before, then clean web browser's cache(or change another name) otherwise (sometimes) it always 404.
The folder META-INF with context.xml is needed.
If you want to create a .war file you can deploy to a Tomcat instance using the Manager app, create a folder, put all your files in that folder (including an index.html file) move your terminal window into that folder, and execute the following command:
zip -r <AppName>.war *
I've tested it with Tomcat 8 on the Mac, but it should work anywhere
(Answers are pretty old, so here's what worked for me on Ubuntu 20.04 Tomcat9)
As root
cd /var/lib/tomcat9/webapps
mkdir -p myapp
cd myapp
cat >>index.html
<html><body>MY SIMPLE PAGE </body></html>
control-D # Press CONTROL+D to exit 'cat', create the file 'index.html'
systemctl restart tomcat9
In browser, use URL: http://127.0.0.1/myapp
(Of course, you can make page fancier, add CSS, etc., etc.)
I struggled a bit with older version of Apache Tomcat (7.0.68) running on Windows Server 2012, but this worked for me after a little bit of experimenting:
Create app folder with your static files (HTML, JS, CSS, assets, etc.).
Inside the folder create META-INF folder and add empty MANIFEST.MF.
Optionally zip the app folder and change the extension to .war.
Upload your app to Tomcat's webapps folder, either as a .war or just folder with your files.
Turned out, that META-INF with empty MANIFEST.MF file is enough for Tomcat to serve the app. No need to add WEB-INF or anything else (at least for my version of Tomcat).
Folder structure:
MyApp (folder)
|--index.html
|--app.js
|--app.css
|--assets (folder)
|--logo.png
|--...
|--META-INF (folder)
|--MANIFEST.MF (empty file)