Multi-client server with DB Authentication!

September 4, 2008 – 7:36 pm
Well I've finally done it! After about a week of coding everyday I've managed to write my own multi threaded web server with username and password authentication, implementing - JSP, HTML, Derby, Tomcat, Java, JDBC and SQL! Oh my was that confusing at times! But now it's done I can start developing cool dynamic web content... :)

A Data Delivery Java Servet Snippet

September 4, 2008 – 3:04 pm
import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.ServerSocket; import java.net.Socket; public class DataServer { public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(1234); while (true) { System.out.println("Listening"); Socket sock = ssock.accept(); DataOutputStream dstream = new DataOutputStream(sock .getOutputStream()); dstream.writeFloat(3.14159265f); dstream.close(); sock.close(); } } } class DataClient { public static void main(String[] args) throws Exception { Socket sock = new Socket(args[0], 1234); DataInputStream dis = new DataInputStream(sock.getInputStream()); float f = dis.readFloat(); System.out.println("PI=" + f); dis.close(); sock.close(); } }

How do I get a password field in a JOptionPane?

September 2, 2008 – 9:56 pm
JPasswordField pwd = new JPasswordField(10); int entered_password = JOptionPane.showConfirmDialog(null, pwd,"Enter Password",JOptionPane.OK_CANCEL_OPTION); Then to get the string use: new String(pwd.getPassword()); The only thing to note is this, because we are using JPasswordField we need to get the JOptionPane output as a integer and then "parse" it to a String (hense the second code fragment - new String(pwd.getPassword()); ).

Install Apache Derby the Java DB

August 26, 2008 – 1:01 am
Phase 1 Introduction This tutorial requires the Java Development Kit (JDK) and the Apache Derby software. First, this section describes which JDK release is required, asks you to install it if you haven't already, then shows you how to configure and verify your installation. Next, it shows you how to install the Apache Derby software, configure your environment to use the Derby Embedded JDBC driver, and verify your installation with the Derby sysinfo tool. Java Development Kit (JDK) Derby requires Java 2 Standard Edition (J2SE) 1.4.2 or higher (this tutorial was developed using JDK 1.5). Only the Java Runtime Environment (JRE) is required to run Derby, but this tutorial compiles a Java application, so it requires the Java Development Kit (JDK). If you already have a JDK installed, verify you are configured to use it, then proceed to the Apache Derby installation section. Install JDK If you have not already installed a JDK, download and install ...