Thursday, October 8, 2009

Web Hosting From Home Using Your Own Computer As The Server

Requirements:
  1. DSL/Cable/Dial-Up any form of home internet connection (which by default has dynamic IP)
  2. TOMCAT Server installed on the computer that you wish to make the server (we will call it Computer#1 henceforth)
  3. Account at http://www.zoneedit.com
  4. A domain name that you would have bought/registered (mydomain.com)
Next do the following:-
  1. Configure TOMCAT to use port 80 on Computer#1. (Optional). For details see HERE. Note: If not configured for port 80 or configured it for any other port, see Step #10 HERE
  2. Configure Computer#1 to have local static IP. For details see HERE
  3. Configure your router to port forward 80 from the IP of Computer#1 (Optional)
  4. Change the routers access port from default (80) to any other port (Optional. This step is needed to prevent conflict, to be on safer side)
  5. Add and configure your domain at http://www.zoneedit.com. For details see HERE
  6. Download and install the IP updater client from http://www.zoneedit.com on Computer#1. Get it from HERE. Use srvany to run it as a Windows service. Get it from HERE
Now you can access your website from outside your network by typing www.mydomain.com in your browser

Ways to include a file in another file

  1. SSI
    Enable SSI in your sever. Then use the following to include one file
    • <!--#include virtual="filename" -->
    • <!--#include file="filename" -->

  2. Include Directive
    <%@ include file="filename" %>

  3. jsp:include Element
    <jsp:include page="filename" />

  4. iframe
    <iframe src="filename" style="height:100%;width:100%;frameborder:0;scrolling:no"> </iframe>


NB: "filename" includes the relative path of the file (with respect to the file that contains include statement) & the filename with its extension (ex. /incl/header.html).

SSIs are a workable solution for including different types of content in your Web site or Web application, but they're not the best choice for Java developers. Not only does JavaServer Pages technology provide an all-Java alternative to SSIs, but the two technologies aren't easily combined. JSP pages end in the extension .jsp, which means that for SSI directives to work you have to either change your SSI configuration to also parse JSP files (adding overhead to every JSP page parse), or change your JSP configuration to treat the .shtml extension as a JSP page (which is a bad idea). JSP technology is the best content management solution for Java developers, and fortunately its include mechanism is a snap to learn.

How to enable SSI in TOMCAT

To enable SSI in TOMCAT do the following:-
  1. Copy manager.xml or host-manager.xml from within C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\Catalina\localhost and paste it in the same folder. Now rename it to MYAPPLICATION.xml MYAPPLICATION should be exaclty same as the application folder name and it should be put inside webapps folder.
    Essentially you want to create an application xml with Context having privileged="true".

  2. opy manager.xml or host-manager.xml from within C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\Catalina\localhost and paste it in the same folder. Now rename it to ROOT.xml. If you don't do this step you will not be able to view/load the default TOMCAT page by using the URL http://localhost:8080/

  3. Open web.xml from C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf and remove the XML comments from around the following:-

    <servlet>
    <servlet-name>ssi</servlet-name>
    <servlet-class>
    org.apache.catalina.ssi.SSIServlet
    </servlet-class>
    <init-param>
    <param-name>buffered</param-name>
    <param-value>1</param-value>
    </init-param>
    <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
    </init-param>
    <init-param>
    <param-name>expires</param-name>
    <param-value>666</param-value>
    </init-param>
    <init-param>
    <param-name>isVirtualWebappRelative</param-name>
    <param-value>0</param-value>
    </init-param>
    <load-on-startup>4</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>ssi</servlet-name>
    <url-pattern>*.shtml</url-pattern>
    </servlet-mapping>

  4. Change the file extension which has the include statement to the appropiate extension as per in the line

    <url-pattern>*.shtml</url-pattern>

    You can change it to any extension you want, provided you make tha same change in url-pattern above.

Sunday, October 4, 2009

Change default port (8080) in TOMCAT

To change the the default port (8080) in TOMCAT do the following:-

Open the file server.xml present in C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf

Look for

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

Change port="8080" to port="80"

<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

You can now access your application by http://localhost/MYAPPLICATION instead of http://localhost:8080/MYAPPLICATION

NB: http://localhost:80/MYAPPLICATION is equivalent to http://localhost/MYAPPLICATION since the default port for http is 80.

Saturday, October 3, 2009

Change default ROOT folder in TOMCAT

When you type http://localhost:8080/ you load the default index.html which is present in C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT. To change this behavior you need to change the redirection to ROOT folder. In order to do that you can implement either of the four options:-
  1. Html redirection from C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\index.html to C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\MYAPPLICATION\index.html
    Modify index.html in C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT as follws:-

    <html>
    <head>
    <title>Redirecting to /MYAPPLICATION</title>
    </head>
    <body onLoad="javascript:window.location='MYAPPLICATION';">
    </body>
    </html>

    Or

    <html>
    <head>
    <title>Redirecting to /MYAPPLICATION</title>
    <meta http-equiv="refresh" content="0;url=MYAPPLICATION" />
    </head>
    <body>
    </body>
    </html>

    NB: MYAPPLICATION is in webapps folder

  2. Add/change context in C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\server.xml inside <Host> tag as follows:-

    <Context path="" docBase="{relative path of MYAPPLICATION folder (relative to webapps folder)} OR {absolute path of MYAPPLICATION folder with backslash or frontslash}" debug="0" >
    </Context>

    NB: Can keep MYAPPLICATION folder anywhere in the computer
    NB: Can leave ROOT folder as it is

  3. Create ROOT.xml in C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\Catalina\localhost as follows:-

    <Context path="" docBase="{relative path of MYAPPLICATION folder (relative to webapps folder)} OR {absolute path of MYAPPLICATION folder with backslash or frontslash}" debug="0" >
    </Context>

    NB: Should keep MYAPPLICATION folder outside webapps folder anywhere in the computer
    NB: ROOT.xml (should be UPPERCASE)
    NB: Can leave ROOT folder as it is

  4. Delete ROOT folder under C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps and rename MYAPPLICATION to ROOT