Archive

Posts Tagged ‘javahosting’

Checking memory usage of your server in Java website hosting

December 5th, 2009 Karthikeyan C No comments

If you host your website on a JEE web or application server on a shared hosting plan (either private or shared instance), you may use the JSP code below to check the memory usage of your server. This will help you to know if the web hosting company really provides you what they promised. This is a simple but efficient tool.


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Your title here</title>
 </head>
 <body>
 <h3>Total memory : <%=Runtime.getRuntime().totalMemory()%></h3>
 <h3>Free memory : <%=Runtime.getRuntime().freeMemory()%></h3>
 <h3>Max memory : <%=Runtime.getRuntime().maxMemory()%></h3>
 <h3>Java version : <%=System.getProperties().getProperty("java.version")%></h3>
 </body>
</html>
  • Share/Bookmark
Categories: Tools / Utilities Tags: ,

Redirecting permanently in HttpServlet from your old domain (website) to new domain

November 29th, 2009 Karthikeyan C No comments

Let us assume we face a scenario where we move from a old domain (website) to a new domain (website). You may do this when you expand your business offering and the old name may not be appropriate.

But your old domain has gained reputation (like a good page rank and a number of incoming links) which you wish to carry forward to your new domain. One way of doing this is respond with HTTP code 301 which is permanently moved.

You may also make use of use Google web master tools to inform the change in domain address (as Google is currently the #1 search engine ). This will prevent the decrease in hits to your website from search engines.

The below code shows how to implement it if you host a Java web application for your old domain.

In web.xml make the below entry.


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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">
 <servlet>
 <servlet-name>RedirectionServlet</servlet-name>
 <servlet-class>com.olddomain.web.servlet.RedirectionServlet</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>RedirectionServlet</servlet-name>
 <url-pattern>/*</url-pattern>
 </servlet-mapping>
 </web-app>

Next the code for RedirectionServlet.java


package com.olddomain.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RedirectionServlet extends HttpServlet {

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {

 //Get the incoming URL request.
 response.setHeader("Location", "http://www.yournewdomain.com"+request.getRequestURI());
 response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
 }

 @Override
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
 processRequest(request, response);
 }

 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
 processRequest(request, response);
 }
}

Note: Using response.sendRedirect will produce only HTTP status code 302 which is temporarily moved and not 301 which indicates it is permanently moved.

  • Share/Bookmark

Affordable Java Hosting providers with good support

November 13th, 2009 Karthikeyan C No comments

Below are few sites where we can host Java JEE applications at a low cost with the availability of good service and support.

www.dailyrazor.com (provides only Tomcat and JBoss as options)

www.rackspacecloud.com (Install any JEE web or application server. You are on your own similar to Amazon EC2).

www.slicehost.com (They say they are linked to www.rackspace.com).

and of course Amazon EC2.

Please feel free to add more hosting services you know in the comments section.

  • Share/Bookmark