CORE API / NOTES</>↗Core API07 Dec 2006
A system properties named user.dir can be used if you want to find the current working directory of your Java program. package org.kodejava.io; public class CurrentDirectoryExample { public static void main(String[] args) { // System property key to get current working directory. String USER_DIR_KEY = "user.dir"; String currentDir = System.getProperty(USER_DIR_KEY); System.out.println("Working Directory: " + currentDir); […]
SERVLET / NOTES</>↗Servlet06 Dec 2006
ServletRequest or HttpServletRequest object has a map object that maps parameter name and its value. By accessing this map we can check if a parameter was passed in servlet request. Let’s see the example below. package org.kodejava.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOExcepti...
SERVLET / NOTES</>↗Servlet06 Dec 2006
This example show you how to obtain parameter name from servlet request. By calling request.getParameterNames() you will get an Enumeration object by iterating this object you can get the parameter names. package org.kodejava.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; im...
SERVLET / NOTES</>↗Servlet03 Dec 2006
When creating an application with Java servlet most of the time we will work with the request and response object. From the request object we can read the parameter submitted by the user’s browser either through an HTTP GET or POST method. Basically what you need to know is when you try to get the […]
CORE API / NOTES</>↗Core API01 Dec 2006
Using the code below you can get a list of country names and its ISO code by using the locale class implementation in Java. package org.kodejava.util; import java.text.Collator; import java.util.*; public class CountryList { public static void main(String[] args) { // A collection to store our country object List<Country> countries = new ArrayList<>(); // Get […]
SERVLET / NOTES</>↗Servlet27 Nov 2006
Here we have a simple example of creating a hit counter using servlet. The servlet updates the hits counter every time a page is visited and display the number of hits as an image. The image is generated at runtime using Java’s java.awt.Graphic2D and javax.imageio.ImageIO class. To store the number of visit data we create […]