SupportWriter space ↗
REFERENCE LIBRARY

References from other publishers

Republished articles with source attribution. This collection is separate from Diary Coding’s original guides and does not display ads.

Read original guides → · Editorial policy

FOR YOUR CURIOSITY

Latest notes.

SERVLET / NOTES</>↗
Servlet16 Jun 2007

How do I invalidate user’s session?

In a web application you might want to invalidate user session, for instance in a logout Servlet or JSP. There is an invalidate() method in the HttpSession interface, this method invalidates the session, and it removes all attributes from the session object. 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.ht...

Wayan · 2 min read
SERVLET / NOTES</>↗
Servlet13 Jun 2007

How do I get client IP and hostname in Servlet?

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; import java.io.PrintWriter; @WebServlet(name = "ClientAddressServlet", urlPatterns = "/client-ip") public class ClientAddressServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest r...

Wayan · 1 min read
CORE API / NOTES</>↗
Core API12 Jun 2007

How do I convert time between timezone?

package org.kodejava.util; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; public class TimeZoneExample { public static void main(String[] args) { // Create a calendar object and set it time based on the local // time zone Calendar localTime = Calendar.getInstance(); localTime.set(Calendar.HOUR, 17); localTime.set(Calendar.MINUTE, 15); localTime.set(Calendar.SECOND, 20); int hour = localTime.get(Calendar.HOUR); int minute = localTime....

Wayan · 1 min read
CORE API / NOTES</>↗
Core API09 Jun 2007

How do I set default Locale?

package org.kodejava.util; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.Random; public class DefaultLocaleExample { public static void main(String[] args) { // Use Random class to generate some random number Random random = new Random(); // We use the system default locale to format a number and a date. NumberFormat formatter = […]

Wayan · 2 min read
CORE API / NOTES</>↗
Core API06 Jun 2007

How do I get response header from HTTP request?

package org.kodejava.net; import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.util.List; import java.util.Map; public class HttpResponseHeaderDemo { public static void main(String[] args) { try { URL url = new URL("https://kodejava.org/index.php"); URLConnection connection = url.openConnection(); Map<String, List<String>> responseMap = connection.getHeaderFields(); for (String key : responseMap.keySet()) { System.out.print(key + " = ");...

Wayan · 1 min read
CORE API / NOTES</>↗
Core API02 Jun 2007

How do I create a URL object?

package org.kodejava.net; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.nio.charset.StandardCharsets; public class URLDemo { public static void main(String[] args) { try { // Creating a url object by specifying each parameter separately, including // the protocol, hostname, port number, and the page name URL url = new URL("https", "kodejava.org", 443, "/index.php"); // We […]

Wayan · 1 min read
✳

Knowledge grows when shared.

Stay curious. There is always something new to learn.

Explore notes ↗
Putu Adi Guna Permana
ABOUT THE AUTHOR

Dr (C). Ir. Putu Adi Guna Permana, S.Kom., M.Kom., IPM., ASEAN Eng.

Writer and founder of Diary Coding — sharing notes, tutorials, and experiences about programming for anyone who wants to keep learning.