Sunday, 3 November 2013

localhost is not working in Xampp after updating Avast

Open Avast
1) Go to "Settings"
2) Go to "Troubleshooting"
3) Expand "Redirect Settings"
4) Under "WEB" look for ignored address
5) Add localhost
6) Open browser and visit your localhost page.

Sunday, 27 October 2013

Keep checkbox checked after submit refresh in PHP

Below code maintain checkbox value when user click preview button


<?php
    if (isset($_POST['number']))
    {
        foreach ($_POST['number'] as $selectednumber)
            $selected[$selectednumber] = "checked";
    }
?>

<form action="" method="post">
    <input type="checkbox" name="number[]" <?php echo $selected['one'] ?> value="one" />one<br />
    <input type="checkbox" name="number[]" <?php echo $selected['two'] ?> value="two" />two<br />
    <input type="checkbox" name="number[]" <?php echo $selected['three'] ?> value="three" />three<br />
    <input type="checkbox" name="number[]" <?php echo $selected['four'] ?> value="four" />four<br />

<input type="submit" name="Submit" value="Preview" />
</form>

Friday, 25 October 2013

How to get previous page url in PHP

$realname = basename($_SERVER['HTTP_REFERER'], ".php");

Multiple submit button in a single form in PHP

<form method="post">
<input type="submit" name="save" value="Submit 1">
<input type="submit" name="cancel" value="Submit 2">
</form>


<?php
if (isset($_POST['save'])) {
  // code
}
else if (isset($_POST['cancel'])) {
  // code
}
?>

Thursday, 24 October 2013

Installing the Java Plugin for Firefox on CentOS

The OpenJDK bundled with CentOS is missing a java plugin for Firefox. A simple method of getting Java to run inside the webbrowser and to run java applications is to install icedtea-web

Open a terminal and type the below command

yum install icedtea-web

Then restart your browser
Click Tools- >Add-ons
The Add-ons Manager tab will open.
In the Add-ons Manager tab, select Plugins
Click icedtea-web plugin to select it and click on the Enable button

The java verification applet (http://www.javatester.org/version.html) works fine.

Installing and configuring Java in cent OS

Most of the Linux operating systems comes with pre-installed OpenJDK package to run java-based applications and plugins.But in certain cases we need Sun/Oracle Java program to compile and run
particular development applications.

1. Download java from  
http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. install java using rpm -uvh
   ## Install Java on 32-Bit OS ##
   # rpm -Uvh jdk-7u45-linux-i586.rpm
   # rpm -Uvh jdk-7u45-linux-i586.rpm

   ## Install Java on 64-Bit OS ##
   # rpm -Uvh jdk-7u45-linux-x64.rpm
   # rpm -Uvh jdk-7u45-linux-x64.rpm

3. check java installed
   # java -version

   output should be
   java version "1.7.0_45"

4. Setting up java environment variables
The easiest way to set an environment variable in CentOS is to use export as in

$> export JAVA_HOME=/usr/java/jdk.1.7.0_45

$> export PATH=$PATH:$JAVA_HOME

However, variables will disappear the moment you exit the shell. Obviously this is not helpful when setting environment variables that need to persist even when the system reboots.In such cases, you need to set the variables within the system wide profile. In CentOS , the folder /etc/profile.d/ is the recommended place to add  customizations to the system profile.

5. Create a new file called java.sh
vim /etc/profile.d/java.sh

6. Copy paste the below content in java.sh

export JRE_HOME=/usr/java/jdk.1.7.0_45/jre
export PATH=$PATH:$JRE_HOME/bin
export JAVA_HOME=/usr/java/jdk.1.7.0_45
export JAVA_PATH=$JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin

7.  If you want to load the environment variables within java.sh without having  to restart the machine, you can use the source command as in:
   $> source java.sh

Wednesday, 23 October 2013

Add horizontal scrollbar to html table

Inorder to add a horizontal scroll bar on html table automatically as the table grows, we need to wrap the table inside a div and add overflow:auto css property

For eg:

<div style="white-space:pre;overflow:auto;width:500px;padding:10px;"> <table style="width:900px;"> <tr> <td>text1</td> <td>text2</td> <td>text3</td> </tr> </table> </div>

Friday, 4 October 2013

Fatal error: Call to undefined function http_redirect() : Fixed

Issue: When I was trying to call the PHP http_redirect() function, below error came up:

Fatal error: Call to undefined function http_redirect() in location.


Add the below function in your php page

/**
 * redirect to a specific URL
 * @param $url
 */
     
function redirect($url)
{
     if (!
headers_sent())
     {  
          
//If headers not sent yet... then do php redirect
          
header('Location: '.$url); exit;
     }
     else
     {                  
          
//If headers are sent... do javascript redirect...
          //if javascript disabled, do html redirect.
          
echo '<script type="text/javascript">';
          echo 
'window.location.href="'.$url.'";';
          echo 
'</script>';
          echo 
'<noscript>';
          echo 
'<meta http-equiv="refresh" content="0;url='.$url.'" />';
          echo 
'</noscript>'; exit;
     }
}  


then call the above function  to the page you wish the redirect to happen on

eg: redirect("redirect.php");




Friday, 12 July 2013

Cannot access xampp from internet in Cent OS

Issue

I have xampp installed on Cent OS. I started the xampp server and tried to access it with localhost, it is working. But i cant access it using the system IP. I can ping the server.But I can't  access the server from any other computer on the network.

Solution

The default firewall of CentOS permits ssh input(tcp 22) and icmp(ping). Open a terminal and type


[root@ ~]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Try at first stopping your firewall issuing the following command:

[root@ ~]# /etc/init.d/iptables stop
Now, test if you can access your XAMPP server.
Go to File System -> etc - >sysconfig
Open iptables. Remove the below line


-A INPUT -j REJECT --reject-with icmp-host-prohibited
 Add the below new line

iptables -A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 80,443 -j ACCEPT
It enables the ports you need to access(80 , 443).
Now your iptables looks like


# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 80,443 -j ACCEPT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Save the file and close it.
Start your firewall issuing the following command:


[root@ ~]# /etc/init.d/iptables start
Now  you can access your XAMPP server using your macine ip address


Wednesday, 26 June 2013

Eclipse donot generate a web.xml while creating dynamic web project

This is beacuse you have'nt check the checkbox for automatically generating the web.xml while creating dynamic web project

1. select File-->New-->Dynamic Web Project
2. After entering the name for your project, click next and next again to get to the "web module" window
3. Click the checkbox "generate web.xml deployment descriptor"

Creating servlet in eclipse with Tomcat

1. Create Dynamic Web Project
   Select from the menu File --> New --> Dynamic Web Project.
  

 2. Check 'Generate web.xml deployment descriptor' checkbox and click "Finish" button and Eclipse IDE will  generate the web project  automatically as shown below




3. Project "helloworld" is created.'


4. You need to add the Servlet API to your classpath.
    refer http://lekshmideepu.blogspot.in/2013/06/the-import-javaxservlet-cant-be-resolved.html
5. Create a Servlet Class
    Create a package under src in your project (say com.hello)
     Right click the package, select new-->servlet.(say HelloWorldServlet as class name).
     Click next and finish

6. Add the below code in 'doGet' method of HelloWorldServlet

          response.setContentType("text/html");
          PrintWriter printWriter  = response.getWriter();
          printWriter.println("<h1>Hello World!</h1>");

         So your HelloWorldServlet  looks like below

package com.hello;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloWorldServlet
 */
@WebServlet("/HelloWorldServlet")
public class HelloWorldServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * Default constructor.
     */
    public HelloWorldServlet() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
          response.setContentType("text/html");
          PrintWriter printWriter  = response.getWriter();
          printWriter.println("<h1>Hello World!</h1>");

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}



7. Create Servlet Mapping in Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
 
  <servlet>
        <display-name>helloworldservlet</display-name>
        <servlet-name>helloservlet</servlet-name>
        <servlet-class>com.hello.HelloWorldServlet</servlet-class>
  </servlet>
  <servlet-mapping>
     <servlet-name>helloservlet</servlet-name>
     <url-pattern>/hello</url-pattern>
  </servlet-mapping>

 
</web-app>

  
9. Add your project to "Tomcat" server and start the server

8. Open a browser and type url:
   http://localhost:8080/helloworld/hello




Friday, 14 June 2013

HTTP Status 405 - HTTP method POST is not supported by this URL

Problem:

When i run my servlet by tomcat server, i got error message
HTTP Status 405 - HTTP method POST is not supported by this URL

Solution

The issue is beacause, you made a HTTP post request from jsp form, but you don't have a doPost() method in the servlet to handle it.
you need to add the below line your servlet class.

public void doPost(HttpServletRequest request, HttpServletResponse response)
 throws IOException{
  ....  
 }

Wednesday, 12 June 2013

Several ports (8005, 8080, 8009) required by Tomcat Server at localhost are already in use

Issue

When you try to run a jsp program on Tomcat server in eclipse, you are getting the below error in the eclipse console
"Several ports (8005, 8080, 8009) required by Tomcat v6.0 Server at localhost are already in use."

Solution

The issue is because you've another instance of Tomcat already running.
To solve this 
1. Go to bin folder of Tomcat  (eg C:\apache-tomcat-7.0.23\bin )
2. Run startup.bat
3. Run shutdown.bat
4. Start the tomcat from eclipse
 

 

The import javax.servlet can't be resolved

Error : The import javax.servlet can't be resolved in eclipse

Soultion

You need to add the Servlet API to your classpath. In Tomcat 7.0, this is in a JAR called servlet-api.jar in Tomcat's lib folder.
steps to add the JAR into your project class path.

Right-click the project, click Properties.
Choose Java Build Path.
Click Add External JARs
Browse to find servlet-api.jar and select it.
Click OK to update the build path.
Clean and build the project

Tuesday, 21 May 2013

Remove Carriage return in varchar column in sql

Issue

I have a mysql table with VARCHAR column which contains String values. Sometimes at the end of the string there is a carriage return (\r). I only want to delete the \r at the end of the string if it exists.

Solution

A carriage return is CHAR(13)

The following code will remove Carriage return 

UPDATE table_name set column_name=REPLACE(column_name,char(13),'')

Remove a character from a string in mysql

Issue 

I have a mysql table with a column name "sequence". sequence column contains protein sequence starting with "protein name > sequence letters"
I need to remove the characters left to ">" including >

for eg: for the input sequence 
Influenza A virus > MKAKLLVLLCAFTATYA
the output should be
MKAKLLVLLCAFTATYA

Solution

You can use SUBSTRING_INDEX(str,delim,count

SUBSTRING_INDEX returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.

you can use

update table_name set column_name = SUBSTRING_INDEX(column_name, '>', -1);



Trim all the values in a column in a sql

Trim all the values in a column in a sql

SQL does not have a trim function. You'll need to use RTRIM and LTRIM together.
update MyTable set Name = RTRIM(LTRIM((name))

Thursday, 16 May 2013

java.lang.classnotfoundexception com.mysql.jdbc.driver in jsp

Issue


When i try to have simple jdbc connection to mysql  in my jsp file, i get following console output in eclipse:
console output in eclipse:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

When i tried to have the same kind of connection from a simple java file it was working.

Solution

You should put the mysql connector JAR file in WEB-INF/lib directory of your project. Clean Build the project and restart the server.


Add Mysql connector in eclipse classpath

Add Mysql connector in eclipse classpath

1. Download mysql connector jar from
http://dev.mysql.com/downloads/connector/j/
2. Open eclipse in java EE perspective (top right corner)
3. Right click the project go to Properties.
4. Choose Java Build Path and then Select Libraries tab
5. Click Add External JARs  and add the path of the mysql connector jar
6. Click Ok button and clean and build the project














Properties window for my java project

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error

Issue

When I try connect my java program to mysql database using eclipse,i am getting the run time error
 "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"

Solution

The reason for the error is you don't have mysql-connector.jar in your Classpath. This jar
contains "com.mysql.jdbc.Driver" class and it must be present in java classpath in order to successful connection to mysql database.
you can downlad mysql-connector.jar from
http://dev.mysql.com/downloads/connector/j/

Click here for adding mysql connector jar to eclipseclass path




Wednesday, 15 May 2013

Php mail tagged as Spam in Gmail Issue fixed

Issue

When I send mail using PHP mail() function,the mail is sent to the Spam folder in GMail.

Solution

You can fix this issue by using the fifth parameter in the mail function to build the header with a valid From address.

PHP Code

<?php 
 
$to 
'you@gmail.com';


$from 'you@yourserver.com';


$message 'Hello';

$subject 'Test Mail';


mail($to$message$subject"From: $from""-f$from");


?> 
 

Monday, 29 April 2013

XAMPP is currently only available as 32 bit application. Please use a 32 bit compatibility library for your system.

XAMPP is currently only available as 32 bit application. Please use a 32 bit compatibility library for your system.

This issue mainly faces when you are trying to install xampp in CentOS. It is because CentOS distro and installation lack many of the libraries  including 32 bit compatibility libraries. So it requires more work to get XAMPP running than on other distros like Ubuntu.

Steps to resolve the issue
1. To get 32 bit compatibility libraries type the below command in terminal
     yum -y install glibc* libstd* ld-linux.so.2
2. Start the xampp from terminal
    /opt/lampp/lampp start 

 

Thursday, 25 April 2013

Install Burrows-Wheeler Aligner (BWA) in Linux

Steps to install BWA in linux machine

1. Download BWA from http://bio-bwa.sourceforge.net/
2. Save bwa-0.7.4.tar.bz2 it to your drive (eg: /usr/username)
3. Open the terminal from /usr/username and untar using the command  tar -xvf  bwa-0.7.4.tar.bz2
4. bwa-0.7.4 folder will be created in /usr/username.
5. Change directory to bwa-0.7.4 using command cd  bwa-0.7.4
6. Type command make
7. Create a file bwa.sh in etc/profile.d
8. Open the file and type
    #!/bin/bash
    BWA_HOME=/usr/username/bwa-0.7.3a
    PATH=$BWA_HOME:$PATH
    export PATH

9. Save and close the bwa.sh
10. Open terminal from etc/profile.d
11. Type command
    chmod 755 bwa.sh
12. To check the installation , open the terminal and type bwa.