Posts

Showing posts from September, 2011

Convert int to String

public class  ConvertIntToString  {    public static  void  main ( String []  args ) {           int  aInt =  1 ;           String aString = Integer.toString ( aInt ) ;         } }

Convert double to string

public class  ConvertDoubleToString  {    public static  void  main ( String []  args ) {      double  aDouble =  0.11 ;      String aString = Double.toString ( aDouble ) ;    } }

Convert string to double

public class  ConvertStringToDouble  {    public static  void  main ( String []  args ) {      String aString =  "78" ;      double  aDouble = Double.parseDouble ( aString ) ;           System.out.println ( aDouble ) ;    } }

Convert String to int

public class  ConvertStringToInt  {    public static  void  main ( String []  args ) {      String aString =  "78" ;      int  aInt = Integer.parseInt ( aString ) ;           System.out.println ( aInt ) ;    } }

Writing a newline in a file using BufferedWriter in Java

This is a writing to include a newline in a file using BufferedWriter in Java. import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; public class WritinginFile {                  public void writingToFile(String fileName){                              BufferedWriter bufferedWriter ;                                      try {                                        bufferedWriter = new BufferedWriter( new FileWriter(fileName));                     ...

Techniques to include other file in case of .htaccess file

If you want to call your .htaccess file something else, you can change the name of the file using the AccessFileName directive. For example, if you would rather call the file .config then you can put the following in your server configuration file, that is, in the httpd.conf file:   AccessFileName .config

Examples on mod_rewrite

1. Description – Your current pages are called using index.php with parameter of url i.e http://www.example.com/index.php?url=category and instead of this URL, you want a nice and easy to read URL like http://www.example.com/category Solution – Put the following lines in your .htaccess file. RewriteEngine on RewriteRule ^([^/\.]+)/?$ /index.php?url=$1 [L] Note : If the .htaccess file already contains a line ‘RewriteEngine on’ then you don’t need to put it again unless it was set to off before you putting in your lines. 2. Description – Your current URL is http://www.example.com/index.php?cat=category&subcat=subcategory which you would like to see as http://www.example.com/category/subcategory Solution – Put the below lines in your .htaccess file RewriteEngine on RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?cat=$1&subcat=$2 [L] 3. Description – You want to have many sub categories or categories like http://www.your-domain.com/category/subcat1/subcat2/su...

Information on .htaccess

Limiting Number of simultaneous connections To limit the number of simultaneous connections to a directory or your entire site , use the below line. If you place it in a directory other than the root directory, then it will limit the connections to that directory and its sub-directories only . Placing it in htaccess file of root directory will implement it for entire site . Syntax: MaxClients < number-of-connections> Examples: MaxClients 40 MaxClients 100 Allow/Disallow certain visitors from accessing your site To accomplish it use the following lines. Look at the syntax first: Syntax: Order allow,deny Deny from < incoming -address > Allow from < incoming -address> The first line [Order allow,deny] tells what should be done first. The second line tells about denying incoming-addresses [could be a single IP, an IP block, domain name and all] and third line tells about the incoming-addresses [could be a single IP, an IP block, domain name and all] thos...

Does your web server support mod_rewrite?

Ensure that you are using Apache web server and mod_rewrite module is installed in your web server. To check this you can either contact your hosting service provider or check it yourself using these simple step. Step1 . Create a blank text file using notepad or any other editor. Step2 . Put <?php phpinfo(); ?> in the file. Step3 . Save as ‘info.php’ . Step4 . Upload the file to your web server’s root or any other folder. Step5 . Call the file in the url – http://your-domain.com/info.php and check if you see mod_rewrite in ‘Apache loaded modules’ section. If NOT, then please contact your hosting provider and request them to install/enable mod_rewrite.

Important Information about .htaccess file

Allow/Deny Directory Browsing When directory browsing is on, people accessing a URL from your site with no index page or no pages at all, will see a list of files and folders. To prevent such directory access , just place the following line in the .htaccess file. IndexIgnore */* Many hosting companies, by default deny directory browsing and having said that, just in case someone need to enable directory browsing , place the following line in the .htaccess file. Options +Indexes Redirect visitors from one page or directory to another It’s quite simple. Look at the example lines below and place similar lines in the .htaccess file of the root folder and it will do the rest. [Remember to use permanent keyword in the line to tell the search engines that the old link has moved to the new link]. You can also setup multiple redirects using htaccess. Syntax : Redirect permanent [old directory/file name][ space ][new directory/file name] Redirect permanent /olddirectory /newdirectory Re...