Generating a Certificate Signing Request (CSR) for Jakarta Tomcat
September 21st, 2009One Comment | Filed Under: Tutorials
Step 1: Prepare your Tomcat server
If you are not using JDK 1.4 or higher, you must download and install “Java Secure Socket Extensions” JSSE.
You can download JSSE from http://java.sun.com/products/jsse/.
Step 2: Generate a Private Key
Use the keytool command to create the private key file:
keytool -genkey -keyalg RSA -keystore yourdomainname.key
The following questions will be asked if not known:
- Enter keystore password: – Tomcat uses a default password of “changeit”. If you use a different password, you will need to specify a custom password in the server.xml configuration file.
- What is your first and last name? – Enter the domain name that you want to use your SSL certificate with.
- What is the name of your organizational unit? – Enter the name of your division, department, or other operational unit of your organization.
- What is the name of your organization? – Enter the name of your organization.
- What is the name of your City or Locality? – Enter the name of your city, town, or other locality.
- What is the name of your State or Province? – Enter the name of the State or Province in which your organization operates. Do not abbreviate.
- What is the two-letter country code for this unit? – Enter the two-letter country code for your country.
You will then be asked if the information is correct:
Is CN=www.yourdomain.com, OU=Your Oganizational Unit, O=Your Organization, L=Your City, ST=Your State, C=Your Country correct?
When you answer y or yes the password is then requested:
Enter key password for <mykey>
Note: Make a note of this password, <mykey> is the default alias for the certificate
Step 3: Create your Certificate Signing Request
Use the keytool command to create the CSR file:
keytool -certreq -keyalg RSA -keystore yourdomainname.key -file yourdomainname.csr
You will be prompted to enter your password.
If the password is correct then the CSR is created otherwise a password error message will be displayed.
You will not be prompted for the common name, organization, etc. The keytool will use the values that you specify when generating the private key.
You have now two files, the Private Key file named yourdomainname.key and Certificate Signing Request (CSR) file named yourdomainname.csr
Conditional Advanced Search Using PHP and MySql
September 18th, 2009No Comments | Filed Under: Tutorials
If you are working on an search page on a site where you have to search the keyword using the following conditions :
1. all the words
2. the exact phrase
3. at least one of the words
4. Without the words
Then you have to use MySQL FullText Search with the Boolean Full-Text Searches functionality to get the desired result.
$option = $_POST['option']; // condition
$keyword = $_POST['keyword']; // keyword
if ($option == "allwords") {
$result = mysql_query("SELECT * FROM db_table WHERE MATCH (field) AGAINST ('{$keyword}' IN BOOLEAN MODE)");
} elseif ($option == "exactphrase") {
$result = mysql_query("SELECT * FROM db_table WHERE MATCH (field) AGAINST ('\"{$keyword}\"' IN BOOLEAN MODE)");
} elseif ($option == "anywords") {
$result = mysql_query("SELECT * FROM db_table WHERE MATCH (field) AGAINST ('{$keyword}' IN BOOLEAN MODE)");
} elseif ($option == "withouttheword") {
$result = mysql_query("SELECT * FROM db_table WHERE MATCH (field) AGAINST ('-{$keyword}' IN BOOLEAN MODE)");
}
?>
Send Simple HTML email with JavaMail
September 15th, 2009No Comments | Filed Under: Tutorials
Send Simple HTML email with JavaMail
The JavaMail API provides a platform-independent and protocol-independent framework to build mail and messaging applications.
This one is the simple program which can be used to send email with JAVA.
import javax.mail.internet.*;
import java.util.Properties;
class SimpleHTMLMail {
public static void main(String[] args) throws Exception{
System.out.println("Sending mail…");
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.mymailserver.com");
props.setProperty("mail.user", "myuser");
props.setProperty("mail.password", "mypwd");
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("HTML mail with images");
message.setFrom(new InternetAddress("you@domain.com"));
message.setContent("<h1>This is a test</h1>"
+ "<img src=\"http://www.domain.com/image.gif\">",
"text/html");
message.addRecipient(Message.RecipientType.TO,new InternetAddress("receive@domain.com"));
transport.connect();
transport.sendMessage(message,message.getRecipients(Message.RecipientType.TO));
transport.close();
}
}