Hey! please help me....


Acutally I need to implement the MD5 algorithm in servlets... I'm strucked at below positions

1. Reading an input to the algorithm

2. saving the output of the algorithm in to database table.... i.e., update the record..

import database.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Test extends HttpServlet
{ Connection con;
Statement stmt;
PreparedStatement pstmt;
public void service(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException
{
String md5val = "12";
MessageDigest algorithm = null;

try
{
algorithm = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException nsae)
{
System.out.println("Cannot find digest algorithm");
System.exit(1);
}

for (String arg : args)
{
byte[] defaultBytes = arg.getBytes();
algorithm.reset();
algorithm.update(defaultBytes);
byte messageDigest[] = algorithm.digest();
StringBuffer hexString = new StringBuffer();

for (int i = 0; i < messageDigest.length; i++)
{
String hex = Integer.toHexString(0xFF & messageDigest[i]);
if (hex.length() == 1)
{
hexString.append('0');
}
hexString.append(hex);
}
md5val = hexString.toString();
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
try{
// Need to read input from md5val

con=DBConn.getConnection();
pstmt=DBConn.prepareStatement("insert into onetimepwd values(?)");
pstmt.setString(1,otpwd);// need to update into the database table

pstmt.execute();
pstmt.close();
out.println("<body bgcolor='#A3A3D1'><center><h1><B><I>Successfully Registered</I>" );
out.print("</B></h1></center></body>");
DBConn.close();
}
catch(Exception e)
{
System.out.println("in userreg");
e.printStackTrace();
System.out.println("in userreg");
}}
}
}


Thank you