New Technologies

  • Java
  • Javascript
  • DTML
  • Dot Net
  • ASP .Net
  • C# .Net
  • PHP
Your Ad Here

Sunday, October 28, 2007

How to Set JNDI in TOMCAT 5.0?

Setting JNDI in tomcat

below is example how to call in java

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

Connection connection = null;
* Getting the JNDI Value from the Properties file which
* are loaded when the tomcat server starts up.

in tomcat "java:comp/env/jdbc/WebPatient"
in Jboss "java:comp/WebPatient"
String strJNDI = "java:comp/env/jdbc/WebPatient"

Context context = new InitialContext();
DataSource data_source = (DataSource) context.lookup(strJNDI);

if (data_source != null)
connection = data_source.getConnection();
catch (Exception e)

end code


Set the follwing in server.xml in config of tomcat before the </host> tag

<Context path="/ContextName" docBase="ContextName" debug="0" reloadable="true" crossContext="false">
<!-- connection pooling -->
<Resource name="jdbc/jndiname" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/jndiname">
<!--MS SQL User name & Password-->
<value>password herelt;/value>
<!--JDBC Driver Class Name-->
<!--MS SQL Server URL-->
<!-- <value>jdbc:microsoft:sqlserver://databaseserver:1433;DatabaseName=databasename;SelectMethod=cursor;ProgramName=progname;autoReconnect=true</value>-->
<!-- To configure a DBCP DataSource so that abandoned dBconnections are removed and recycled -->
<!--Use the removeAbandonedTimeout parameter/seoonds.-->
<!-- Maximum number of dB connections in pool. Set to 0 for no limit. -->
<!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit.-->
<!-- Maximum time to wait for a dB connection to become available in ms;
Set to -1 to wait indefinitely. -->
<!-- End of addition for Connection Pooling-->

Tuesday, October 9, 2007

TOMCAT 5.0 SSL Configuration



Using Keytool generate a keystore

keytool -genkey -alias -keyalg RSA -keystore


Then the key tool will ask for password give that . Then it is ask for the first name give the system name where the certificate is installed or the URL which is used to access from the browser.

What is your first and last name?

[Unknown]: Satish(System name)

What is the name of your organizational unit?

[Unknown]: satish

What is the name of your organization?

[Unknown]: credense

What is the name of your City or Locality?

[Unknown]: hyd

What is the name of your State or Province?

[Unknown]: ap

What is the two-letter country code for this unit?

[Unknown]: in

Is CN=satish, OU=satish, O=credense, L=hyd, ST=ap, C=in correct?

[no]: y

Enter key password for

(RETURN if same as keystore password):


Export a public key to a file

keytool -export -file -keystore -alias


The below step is not necessary if we give the path in the startup.bat

The trustStore is the path and name of the java key store (jks)

And the truststorepassword is the password for the keystore.

If we have not given this tomcat will take the default keystore as j2sdk1.4.2_10\jre\lib\security\cacerts and the default password is “changeit” if we have not given the string . in startweblogic.cmd.

set JAVA_OPTS="D:\Satish\ssl\keys\allcerts.jks"

The following step in not required if we have done the above:

Then import the above-generated public key to


Import the Weblogic public key to the above tomcat keystore if tomcat has to communicate with weblogic.


keytool -import -keystore test.keystore -file satishcrt.pem


And also import the tomcart Certificate to weblogic keystore to communicate from tomcat to weblogic


keytool -import -keystore satish.jks -file abc.crt


Configuring the server.xml file

Open the server.xml file in config folder of Tomcat.

Place or modify the following tag in server.xml

maxThreads="150" minSpareThreads="25" maxSpareThreads="75"

enableLookups="false" disableUploadTimeout="true"

acceptCount="100" debug="0" scheme="https" secure="true"

clientAuth="false" sslProtocol="TLS" KeystoreFile="D:\Satish\ssl\keys\tomeg.jks" KeystorePass="changeit" />

port : Port of the tomcat

KeystoreFile: Name and path of the tomcat Keystore .

KeystorePass: Password of tomcat keystore.


Modify the .java files where the port numbers and the protocol is given like

http:// à https://

for tomcat 8080à8443

for Weblogic 7001à 7002

Your Ad Here