How to set the Java servlet session timeout

3

Java servlets have a lot of functions to manage user sessions. If you want to set the session timeout, you can use the function setMaxInactiveInterval(). Before you can set the timeout value, you have to get the session object.You can also provide a negative value here to indicate that the session never expires. (value is -1)

Here a sample:

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

   HttpSession session = request.getSession();

   /* Set session timeout in minutes */

   int MaxUserSessionInactiveInterval=60;

   session.setMaxInactiveInterval(MaxUserSessionInactiveInterval * 60);

}

The value inside setMaxInactiveInterval is defined in seconds. So you must multiply the value x 60.

How to set the mouse cursor into a HTML formular field

0

If you want to focus the mouse pointer into a formular field you have to do the following things:

1.) Create the HTML formular and add the following lines to the body tag.

<body onload="setMouseFocus();">
<form action="LoginServlet" method="post" name="loginformular">
 <input type="text" name="username" size=50 maxlength=255 value="">
</form>
</body>

2.) Add the following lines to the HTML header.

<script>
<!--
function setMouseFocus() {
 document.loginformular.username.focus();
}
// -->
</script>

That’s all! The mouse cursor will focus the formular field “username” when the page has been loaded.

How to call a Java servlet from JSP (Java Server Page)

2

 

Java Servlets and JSPs are components that running on server side. Servlets contains the logic of the application code and JSP (Java Server Pages) formatting the output for the user interface (GUI). Sometimes we need to call a servlet from a JSP to get information from a database.

In my sample I call Servlet "PageServlet" with parameter "getTitle" and "TitleName". The Servlet create for my JSP page the HTML code with title, font type, font size and color for me. This helper function support me to have the same look on all the pages in my web application.

Sample JSP:

CallServletFromJSP.jsp

 

<%
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/PageServlet?method=getTitle&TitleName=Title of current JSP page");
dispatcher.include(request,response);
%>

 

Simple AJAX sample using Java servlets and Java Script

3

Ajax provides a lot of possibilities to make your application "Web 2.0" ready. One of the big pro is that you can change some parts of the website without a reload of the whole webpage. Here is a short and very simple sample to sent a Ajax request from a HTML form to a Java servlet and back. The servlet will response with the characters that has been sent to the servlet. It’s just a loop from HTML to servlet and back again.

...


var xmlHttp;// global instance of XMLHttpRequest
function createXmlHttpRequest()	{
       if(window.ActiveXObject) {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      	}
		else if(window.XMLHttpRequest) {
        	xmlHttp=new XMLHttpRequest();
     	}
}

function startRequest() {
  createXmlHttpRequest();

  var uv1=document.f1.uservalue.value;
  xmlHttp.open("GET","http://localhost:8080/ITest/ResponseServlet?uservalue="+uv1 ,true)
  xmlHttp.onreadystatechange=handleStateChange;
  xmlHttp.send(null);

}

function handleStateChange() {
    if(xmlHttp.readyState==4) {
        if(xmlHttp.status==200) {
          	 var message = xmlHttp.responseXML.getElementsByTagName("valid")[0].childNodes[0].nodeValue;
             document.getElementById("results").innerHTML=message;
        }
        else {
           alert("Error loading pagen"+ xmlHttp.status + ":"+xmlHttp.statusText);
        }
    }
}



Insert your characters:  
...
package SimpleAjaxResponse;

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

/**
 * Servlet implementation class ResponseServlet
 */
public class ResponseServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public ResponseServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String FormField = request.getParameter("uservalue");

		response.setContentType("text/xml");
		response.setHeader("Cache-Control", "no-cache");
		response.getWriter().write("Response (Your characters are: "+FormField+")");

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

How to create shortcuts on USB flash drives (U3) or removable medias?

6

The following article describes how to create a shortcut on the root directory of an USB flash drive or other removable medias. Following are the three main steps:

  • Create a batch file
  • Extract the ICO picture from the original application
  • Compile batch + ICO file to a execuable file

 

The problem: Why do we need relative shortcut path? If you plugin the USB flash drive to your computer, Windows XP will change the drive letter every time. This causes that the absolute path to the application.exe on a USB flash drive breaks continuously. The easiest solution is to use relative paths instead of absolute paths. However we have the another problem:

Windows XP doesn’t support relative path information in shortcuts. That means just absolute paths are supported. Here`s a sample:

  • relative paths: ../other_subfolder/application.exe
  • absolute path: k:\other_subfolder/application.exe

 

The solution: Okay, now you know what the problem is with shortcuts and paths. Let’s start with the solution step by step:

  1. Create a new text document and rename it as myshortcut.txt
  2. Open it and type in the path for the executable, (the quotes are required)
    start “../other_subfolder/application.exe” . Save and exit.

     

     


     

  3. Change the extension of the text file myshortcut.txt to myshortcut.bat (the extension BAT stands for batch script)
  4. In the next step we have to extract the icon from the original application.exe and save it as an ICO file. For this action you can use the program “BecyIconGrabber“.
  5. Now, you must convert the file myshortcut.bat with your ICO file to an executable file named myshortcut.exe. To do this, you can use the freeware tool “Bat To Exe Converter”. In the program dialog, you must choose the file myshortcut.bat and the ICO file. After that you use the “Compile”-button to create the execuable file myshortcut.exe
  6. Now place the myshortcut.exe file to the root of your USB flash drive. That’s all!

Windows XP will now identify the myshortcut.exe and this execuable file will call the application as  ../other_subfolder/application.exe.

 

 

Synchronize the computer time with an Internet time server

0

Frequently I have problems with a wrong computer clock. Windows XP provides the option to automatically synchronize the clock on your system with an Internet time server. Windows provides, by default, only two servers. Sometimes the synchronization with these two servers isn’t reliable.

The following steps explain you how to change the time server with one of your local country’s:

1.) Doubleclick on the time in the taskbar
2.) Go to the tab "Internet Time"
3.) Enable the switch "Automatically synchronize with an Internet time server" and enter one of the following Server names from the list below.

That’s all!

 

 

Here’s a list of time servers around the world. It’s also possible to select another time server which is not located in your home country.

 

Server ip Server name
Germany (DE)  
151.189.0.34 ntp1.arcor-online.net
213.133.111.196 crux.pmsf.net
77.37.6.59 ntp.dianacht.de
134.34.3.19 ntp2.rz.uni-konstanz.de
   
Netherlands (NL)  
195.241.158.50 195-241-158-50.ip.telfort.nl
   
United Kingdom (UK)  
130.88.200.4 dir.mcc.ac.uk
130.88.212.143 turnip.mc.man.ac.uk
   
France (FR)  
192.93.2.20 canon.inria.fr
88.191.11.98 ntp.home-dn.net
   
Irland  (IE)  
140.203.16.5 MSC-101.it.nuigalway.ie
   
Canada (CA)  
142.3.100.15 SUE.CC.UREGINA.CA
   
USA (US)  
131.216.1.101 cuckoo.nevada.edu
66.27.60.10 ntp.drydog.com
128.101.101.101 ns.nts.umn.edu
Brazil (BR)  
200.160.0.8 a.ntp.br
   
Japan (JP)  
133.100.9.2 clock.nc.fukuoka-u.ac.jp
   
 China (CN)  
218.75.4.130 hshh.org
   
New Zealand (NZ)  
139.80.64.114 ntp.public.otago.ac.nz

 

Access VMware ESXi server with vijava API (your own developed Java software)

9

With vijava you have the possibility to setup, control and monitor virtual machines with your own developed Java software. A huge disadvantage is that some feature are restricted in VMware ESXi server. That means, that simple features (Create virtual machines, modify and delete virtual machines) are only available in commercial versions of VMware, like VMware Infrastructure. But nevertheless, we are looking forward and I like to show you a sample. :-)

Background information:

vijava 2 is a API was open sourced at sourceforge.net under BSD license in May 2008. The offical website is http://vijava.sourceforge.net/. The vijava API can be used with Eclipse. If you haven’t done so, you can go to http://www.eclipse.org to download and install it. Please follow the tutorial on http://vijava.sourceforge.net/doc/getstarted/tutorial.htm to setup Elipse and create a new project.

The following sample code sends a request to the VMware ESXi server to standby the virtual machine with name Test_VM:

 

import java.net.URL;
import com.vmware.vim25.CustomFieldDef;
import com.vmware.vim25.Permission;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.Task;
import com.vmware.vim25.mo.VirtualMachine;  

/**
* http://vijava.sf.net
* @author Steve Jin / Modified by Michael Hopf
*/  

public class VMpowerOps  {   

public static void main(String[] args) throws Exception    {           

String vmname = "Test_VM";
/* other ops: reboot|poweron|poweroff|reset|standby|suspend|shutdown */
String op = "standby";     

ServiceInstance si = new ServiceInstance(new URL("https://server1.fireline.de/sdk"), "root", "password", true);
Folder rootFolder = si.getRootFolder();

VirtualMachine vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmname);

   if(vm==null)
    {
      System.out.println("No VM " + vmname + " found");
      si.getServerConnection().logout();
      return;
    }

    if("reboot".equalsIgnoreCase(op))
    {
      vm.rebootGuest();
      System.out.println(vmname + " guest OS rebooted");
    }
    else if("poweron".equalsIgnoreCase(op))
    {
      Task task = vm.powerOnVM_Task(null);
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " powered on");
      }
    }
    else if("poweroff".equalsIgnoreCase(op))
    {
      Task task = vm.powerOffVM_Task();
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " powered off");
      }
    }
    else if("reset".equalsIgnoreCase(op))
    {
      Task task = vm.resetVM_Task();
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " reset");
      }
    }
    else if("standby".equalsIgnoreCase(op))
    {
      vm.standbyGuest();
      System.out.println(vmname + " guest OS stoodby");
    }
    else if("suspend".equalsIgnoreCase(op))
    {
      Task task = vm.suspendVM_Task();
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " suspended");
      }
    }
    else if("shutdown".equalsIgnoreCase(op))
    {
      Task task = vm.suspendVM_Task();
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " suspended");
      }
    }
    else
    {
      System.out.println("Invalid operation. Exiting...");
    }
    si.getServerConnection().logout();
  }
}

Running Feedreader from USB flash drive

1

Feedreader3 is one of the most popular feedreaders around the world. Feedreader3 is a product of i-Systems Inc. in Estonia. I use it, because it has a user-friendly design with a lot of features. Now I like to explain, what you must configure so that Feedreader3 can be started from USB flash drive.

You must perform the following steps to change the database location of Feedreader3 :

1.) Install Feedreader3 to your USB flash drive (during the installation process you will be asked to use Feedreader3 on USB drive. Check this box)

2.) After the installation process has finished, move feedreader.ini from folder c:\Documents and Settings\[USERNAME]\Application Data\Feedreader\ to the folder where Feedreader application files are located (in my case f:\programs\feedreader30).

3.) Create a folder with the name DATA in the Feedreader3 installation directory (in my case f:\programs\feedreader30\DATA).

4.) Move rssengine.fdb file from c:\Documents and Settings\[USERNAME]\Application Data\Feedreader\ to DATA folder.

That’s all! From now on, Feedreader3 will store all feed data in directory DATA (file RSSENGINE.FDB) .

 

How to create mail rules in Mozilla Thunderbird ?

0

I really like Thunderbird and the way I’m able to manage E-Mails, address book and calendar all within the same program. I’m using Thunderbird version 3.0.4 with the following extensions: Adblock Plus, BirdieSync, Lightning and Personas.

It’s really easy to create mail rules in Thunderbird! Thunderbird contains mail rules without installing any addional packages, called Add-ons. For example in my sample I like that every incoming mail with mail subject "Newsletter Amazon" are moved to a separate folder named "Newsletter". To do this, you must perform the following steps:

1.) Go to your personal Inbox folder
2.) Click on Message -> Create Filter From Message
3.) Enter a filter name, here we use "Move newsletter from amazon to newsletter folder"
4.) Select "Subject contains Newsletter Amazon" as an if condition
5.) Now you must set an action for this condition: Here we like to move the message to our Newsletter folder in Local Folders

Click OK to save the new mail rule. That’s all! From now on each new newsletter mail will be moved to the newsletter folder. Last but not the least, a picture of the rule setting:

 

 

Sinnvolle Webseiten für das Handy

0

Mobiles surfen im Internet ist bereits sehr beliebt geworden. Mal möchte man schnell bei Google Maps nach einer Straße schauen oder ein englisches Wort bei LEO übersetzen. Die verfügbaren Handy sind mittlerweile brauchbar, um unkompliziert einfache Inhalte darzustellen. Für längere Artikel sowie Bilder sind die Displays aber immer noch zu klein.

Hier nun eine Liste der für mich besten mobilen Webseiten:

Platz
mobile Webseite Kurze Beschreibung
1 Wikipedia Wikipedia nahm ab Herbst 2009 eine neue Webseite für Smartphones in Betrieb
2 Google Wer kennt Google nicht ;-) Größte Suchmaschine der Welt auch für mobiles Surfen
3 LEO Wörterbuch Eines der besten Wörterbuch im deutschsprachigen Raum
4 Google Maps Mit Google Maps einfach Karten, Orte und Objekte anzeigen
5 Deutsche Post Filialen suchen, eine Sendung verfolgen oder nur das Porto erfragen..
6 Deutsche Bahn Eine Zugverbindung suhen reicht mir meist schon ;-)
7 heise mobile Nachrichten aus der Informations- und Telekommunikationstechnik
8 Amazon Bücher und andere Sachen über das Handy anschauen und Preise vergleichen
9 eBay eBay für die Nutzung auf dem Handy
10 Spiegel Mobile
Spiegel Online fürs Handy
Weitere Seiten…
  meinVZ Das größte deutschsprachige soziale Netzwerk
  XING Das bekannteste deutsche soziale Netzwerk für Geschäftskontakte
  Facebook Das größte und internationale soziale Netzwerk weltweit
  Twitter Für Leute für ein großes Mitteilungsbedürfnis haben

 

Go to Top