4

I made a small static website for my client and now they want me to replace their present dynamic website with the static one. They have Ubuntu with SSH installed on the remote location. Their existing website is running on a Tomcat6 server and the site root is in "/var/lib/tomcat6/webapps/ROOT/".

My website consists of just static HTML pages. How can I reconfigure/ replace the present website with the one I made? Should I just stop the server and replace the files in the site root with my files?

Adding the updated web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5">

  <display-name>Welcome to OneLearn</display-name>
  <description>
     Welcome to OneLearn
  </description>
  <session-config>
    <session-timeout>60</session-timeout>
  </session-config>


<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>


<servlet>
<servlet-name>linegraph</servlet-name>
<servlet-class>com.FlexiApps.graphs.LineGraphServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>linegraph</servlet-name>
<url-pattern>/linegraph</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>piechart</servlet-name>
<servlet-class>com.FlexiApps.graphs.PiechartServlet</servlet-class>
</servlet>

<servlet-mapping>
ssawqfxz<servlet-name>piechart</servlet-name>
<url-pattern>/piechart</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>welcome</servlet-name>
    <servlet-class>com.FlexiApps.utils.welcome</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>welcome</servlet-name>
    <url-pattern>/welcome</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.jpg</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.png</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.js</url-pattern>
</servlet-mapping>

<welcome-file-list>
        <welcome-file>index.html</welcome-file>
</welcome-file-list>

<jsp-config>
  <taglib>
    <taglib-uri>http://jakarta.apache.org/taglibs/log-1.0</taglib-uri>
    <taglib-location>/WEB-INF/lib/taglibs-log.tld</taglib-location>
  </taglib>
</jsp-config>

      <listener>
  <listener-class>
    org.apache.commons.fileupload.servlet.FileCleanerCleanup
  </listener-class>
</listener>


</web-app>

Even after adding a welcome-file and adding the suggested servlet mappings, tomcat doesn't seem to detect any new files added to the ROOT folder.

Ashin Mandal
  • 463
  • 1
  • 6
  • 19

3 Answers3

2

I found a work-around to my problem:

  1. I installed Tomcat6 on my Eclipse in Windows.
  2. I created a Dynamic Web Project.
  3. Put all my static content in the WebContent folder.
  4. Ran the server to verify everything is in order.
  5. Exported a WAR file from the project, checked "Optimize for a specific server runtime" option, runtime being "Apache Tomcat v6.0".
  6. I cleaned up the /var/lib/tomcat6/webapps/ROOT folder on the ftp linux server and reset all other settings to default.
  7. Extracted the WAR file in ROOT folder.
  8. Restarted tomcat6 using: /etc/init.d/tomcat6 restart
  9. I could successfully see my static website under "http://myIP:8080/"
  10. I wanted tomcat6 to work without this port number. The following link was very useful: http://bhou.wordpress.com/2012/03/09/how-to-install-and-configure-tomcat-6-in-ubuntu-server/
  11. My static website could be navigated to by typing in "http://myIP/"

Eclipse generated web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>StaticWebsite</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>
Ashin Mandal
  • 463
  • 1
  • 6
  • 19
0

If its the only site running on the server the easiest way is as mentioned to copy your files in the same location and to name the start site with the same name as their startsite, in this case you dont need to change the configuration. Otherwise check this link: Tomcat 6: How to change the ROOT application

EDIT (from here):

The contents of the default Tomcat home page comes from the ROOT webapp servlet called org.apache.jsp.index_jsp. The page that you see in $CATALINA_HOME/webapps/ROOT/index.jsp has been precompiled into a class file (org.apache.jsp.index_jsp.class) stored in a JAR file (catalina-root.jar) in the ROOT webapp's WEB-INF/lib directory. Because of this servlet, Tomcat will not look at the contents of the ROOT web application's index.jsp file if you change it.

The easiest way to change the contents of the index.jsp page is to remove this index_jsp servlet from the ROOT webapp. Once you remove the index_jsp servlet and restart Tomcat, Tomcat will see the index.jsp file in the ROOT directory and compile it on the fly into a class file. You now will be able to edit the ROOT/index.jsp file and have those changes take effect immediately by reloading the "http://localhost:8080/" page.

Community
  • 1
  • 1
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
  • I am sorry but what do you mean by start site? I just tried renaming my home page to index.jsp and replacing it with the existing one. That did not work. – Ashin Mandal Jun 05 '12 at 05:14
  • There wasn't a 'org.apache.jsp.index_jsp' to be commented out. I have added the updated web.xml to my question. – Ashin Mandal Jun 05 '12 at 09:54
0

http://www.java-only.com/LoadTutorial.javaonly?id=26

This blog seems to provide a step by step instructions on serving static content using tomcat.

ShaggyInjun
  • 2,880
  • 2
  • 31
  • 52
  • 1
    I am looking for a way to change the start page of the website to be index.html (my file) instead of index.jsp (the existing one). The blog has described servlet mapping for static files. I want the home page of the website to be changed. – Ashin Mandal Jun 05 '12 at 05:51
  • Change the existing welcome file configuration to this inside your web.xml. index.html – ShaggyInjun Jun 05 '12 at 06:28
  • I added a welcome-file but it still goes to the 404 page. Added web.xml to my question. – Ashin Mandal Jun 05 '12 at 09:55