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.


Friday 15 March 2013

Setting java path in linux

After installing JDK or JRE on Linux/Unix platform, you have to set PATH environment variable so that you can run the executables (javac.exe, java.exe, javadoc.exe, and so on) from any directory without having to type the full path of the command.
 
 Steps to set up java path in linux

1. Create a java.sh file in /etc/profile.d directory with content as follows: 
 
#!/bin/bash
           
JAVA_HOME=/usr/java/jdk1.7.0_17
                    
PATH=$JAVA_HOME/bin:$PATH
                                       
export PATH JAVA_HOME
 
The file contains various shell commands which set and export necessary environment variables for Java. Shell settings from configuration files in the /etc/profile.d directory are gathered by/etc/profile during login, setting up user environment information for every user.  
 
2.  Assign execute permissions:
 
# chmod 755 java.sh

3. You can verify the path  by typing the below command in the terminal

# java -version