I am getting java.security.InvalidKeyException: Illegal key size or default parameters , I have fallow all the required step ,Installed Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files.
Also I have Gone through these Threads
Since the exception is thrown from within a servlet and we can't see the parameters you are using and how you are using this code it is difficult to help. Your best bet is to create and post a stand alone test harness that illustrates the problem and that does not involve your servlet.
Having looked in more detail at your code it seems to be nonsense and cobbled from code used for a very different purpose. Presumably the String 'dhkey' was originally a Diffe-Hellman parameter but I have no idea how the names of the methods generate_r() and generate_k() relate to their current functionality. You also need to work on your exception handling since it is dreadful.
P.S. Are you sure you have installed the Unlimited Strength files in the JDK being used to run your application server?