JavaTechie

Its all about Technology

Display specific length string without truncating word in Java June 25, 2009

Filed under: Java, PHP — javatechie @ 5:29 am
Tags:

public static String textSubString(String text, int start, int end){

String str=”";
int limit=0;
limit=end;

if(text.length()!=0 && text!=”"){

String substr=text.substring(end,end+1);

if(substr!=”"){

while(!substr.equals(“”)){

substr=text.substring(limit,++limit);
substr=substr.trim();

}
}

str=text.substring(start,limit);

}

return str;
}

 

Java method similar to nl2br in PHP June 25, 2009

Filed under: Java, PHP — javatechie @ 5:26 am

public static String nl2br( String text){

return text.replaceAll(“\n”,”<br />”);

}

 

Directory index forbidden by Options directive June 8, 2009

Filed under: Apache — javatechie @ 12:29 pm
Tags: ,

I was going through error log and saw this error in error log file. To solve this problem, In /etc/httpd/conf.d you will see a file entitled welcome.conf

It looks like this:

<LocationMatch “^/+$”>
Options -Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>

Change it to this:

<LocationMatch “^/+$”>
Options Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>

Just remove the hyppen(-) before the Indexes, that’s it. I hope this will solve your problem.

 

Make sshd listen to a specific address June 8, 2009

Filed under: Uncategorized — javatechie @ 12:10 pm

In file /etc/ssh/sshd_config,
use

ListenAddress 192.168.0.1

to make sshd listen to only that address.

 

PHP- session Example June 3, 2009

Filed under: PHP — javatechie @ 12:33 pm

<?php
// Initialize the session.
session_start();
//store values
$_SESSION['favcolor'] = 'green';
$_SESSION['animal']   = 'cat';
$_SESSION['time']     = time();

//print stored values

echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date('Y m d H:i:s', $_SESSION['time']);

// Unset all of the session variables.
$_SESSION = array();

// Finally, destroy the session.
session_destroy();

?>