import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Niraj Chauhan
*/
public class DownloadFile extends HttpServlet {
protected synchronized void processRequest(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String filePath=request.getParameter("filePath");
System.out.println("filePath = "+filePath);
String fileName="file1";
if(filePath == null)return;
if(filePath.contains("/")){
String[] b = filePath.split("/");
fileName=b[b.length-1];
}
response.setHeader("Content-Length", String.valueOf(new File(filePath).length()));
response.setContentType( "application/octet-stream" );
//response.setContentType("application/vnd.ms-excel");
// System.out.println(".......response.getContentType() = "+response.getContentType());
response.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");
FileInputStream inputStream = null;
try
{
inputStream = new FileInputStream(filePath);
System.out.println(" INPUTSTREAM CREATED");
byte[] buffer = new byte[1024];
int bytesRead = 0;
do{
bytesRead = inputStream.read(buffer, 0, buffer.length);
response.getOutputStream().write(buffer);
}while (bytesRead == buffer.length);
System.out.println(" END OF WHILE");
response.getOutputStream().flush();
System.out.println(" FLUSHING DONE");
}catch(Exception e){
System.out.println("Exception in DownloadFile.java ="+e);
}finally{
if(inputStream != null)
inputStream.close();
System.out.println(" INPUT STREAM CLOSED");
}
}
//
/**
* Handles the HTTP GET method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP POST method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}//
}
software company in anand gujarat that focuses on website development, web hosting solutions, Android Development and Embedded Software Development which is founded in 2012. Purely focused on Opensource Initiative.
23 March 2013
JAVA SERVLET CODE TO DOWNLOAD A .txt file
19 March 2013
Convert JAVA DATE to MS SQL datetime format
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date javaDate=new Date();
System.out.println("Java Date : "+javaDate);
String msSqlDate=sdf.format(javaDate).trim();
System.out.println("Ms Sql Date : "+msSqlDate.replace(" ","T"));
insert into DATA (CREATED) values (convert(datetime,'"+msSqlDate+"'));
JAVA CODE FOR LEFT SHIFT AND RIGHT SHIFT AND BITWISE OPERATOR
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] rk) {
// range of int -2,147,483,648 to 2,147,483,647
// int is 32bit so below i have taken 32bits
int a=10; // a= 00000000 00000000 00000000 00001010 = 10 [ten]
a=a<<2; // left shift operator
//now a=00000000 00000000 00000000 00101000 = 40 [fourty]
System.out.println("a="+a);
// same way right shift operator
int b=2; // ..... 00000010
int c=2; // ..... 00000010
int d= c& b; //...00000010
System.out.println("[logican AND] c ="+c);
d=c|b;
System.out.println("[logical OR] c ="+c);
// same way change value of b=1 and c=2 then you could uderstand how it works bit by bit.
}
}
java interfeces
JAVA :READ SOMETHING IMPORTANT ABOUT INTERFACE
i) All interface methods are implicitly public and abstract. In other words,
you do not need to actually type the public or abstract modifiers in the
method declaration, but the method is still always public and abstract.
ii) All variables defined in an interface must be public, static, and final—
in other words, interfaces can declare only constants, not instance variables
iii) Interface methods must not be static.
iv) Because interface methods are abstract, they cannot be marked final,
strictfp, or native.
v) An interface can extend one or more other interfaces.
vi) An interface cannot extend anything but another interface.
vii) An interface cannot implement another interface or class.
viii) An interface must be declared with the keyword interface.
ix) Interface types can be used polymorphically
i) All interface methods are implicitly public and abstract. In other words,
you do not need to actually type the public or abstract modifiers in the
method declaration, but the method is still always public and abstract.
ii) All variables defined in an interface must be public, static, and final—
in other words, interfaces can declare only constants, not instance variables
iii) Interface methods must not be static.
iv) Because interface methods are abstract, they cannot be marked final,
strictfp, or native.
v) An interface can extend one or more other interfaces.
vi) An interface cannot extend anything but another interface.
vii) An interface cannot implement another interface or class.
viii) An interface must be declared with the keyword interface.
ix) Interface types can be used polymorphically
Set CSS Using JavaScript
function setSCC(){
var element=document.getElementById("add"); element.className='btn_disable';
element.style.height="100px";
element.style.width="200px";
element.disable=true;
}
Note : Above function can get the element having id="add". and it will set its css class to "btn_disable" and will set it height and width as specified , as well as it will disable the button.
u should have the css included in your page.
common.css
--------------------
.btn_disable
{
font-family: Arial;
font-size:10pt;
height:30px;
background-color:gray;
color:red;
}
JAVA SCRIPT TO VALIDATE TIME IN "dd-mm-yyyy hh:mm:ss" FORMAT
function validateStartTime() {
//This function will validte the datetimes of this format : dd-mm-yyyy hh:mm:ss
var date = document.getElementById("startTime").value.trim();
var valid = true;
var spaceIndex = date.indexOf(" ");
var onlyDate = date.substring(0,spaceIndex);
var dateData = onlyDate.split("-");
var onlyTime = date.substring(spaceIndex);
var timeData = onlyTime.split(":");
var day = (dateData[0]);
var month = (dateData[1]);
var year = (dateData[2]);
var hour = (timeData[0]);
var min = (timeData[1]);
var sec = (timeData[2]);
var regForDate = new RegExp("\\d{1,2}-\\d{1,2}-\\d{4}$");
var regForTime = new RegExp("\\d{1,2}:\\d{1,2}:\\d{1,2}$");
if(!regForDate.test(onlyDate)) valid =false;
else if(!regForTime.test(onlyTime)) valid =false;
else if((month < 1) || (month > 12)) valid = false;
else if((day < 1) || (day > 31)) valid = false;
else if(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && (day > 30)) valid = false;
else if((month == 2) && (((year % 400) == 0) || ((year % 4) == 0)) && ((year % 100) != 0) && (day > 29)) valid = false;
else if((month == 2) && ((year % 100) == 0) && (day > 29)) valid = false;
else if((hour < 0) || (hour > 24)) valid = false;
else if((min < 0) || (min > 59)) valid = false;
else if((sec < 0) || (sec > 59)) valid = false;
return valid;
}
JAVA SCRIPT TO ALLOW ONE SPACE BETWEEN WORDS
function removeExtraSpaces(){
var searchName = document.getElementById(“name”).value;
searchName = searchName.trim();
var words = searchName.split(” “);
var updatedName=”";
if(words.length>1){
for(var i=0; i if(words[i]!=”"){
updatedName += words[i]+” “;
}
}
document.getElementById(“name”).value=updatedName;
}
}
Java code to generate unique random key
import java.util.Random;
public class RandomKeyGenerator {
public static String generateRandomKey() {
String allChars = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@$%^*()_”;
Random random = new Random();
int length = random.nextInt(5);
length+=7;
char[] chars = new char[length];
for (int i=0; i chars[i] = allChars.charAt(random.nextInt(allChars.length()));
}
return new String(chars);
}
}
9 March 2013
FAT DOG 64-bit Operating System.
Fatdog64 is a small yet versatile 64-bit multi-user Linux distribution. Originally created as a "fatter" (=more built-in applications) derivative of Puppy Linux, Fatdog has grown to become a completely separate, mature 64-bit distribution. Fatdog64 still embodies the Puppy Linux spirit, fast and efficient.
At around 200MB, Fatdog boots up to a complete desktop environment ready for use; most everyday application is already included.
- Web browser (Seamonkey browser - which uses identical code base as Firefox)
- Universal email client (Seamonkey Mail)
- Versatile media player (VLC)
- Bit torrent client (Transmission)
- Word processing (Abiword)
- Spreadsheet (Gnumeric)
- PDF/PS/Djvu reader (Evince)
- PDF annotation (Xournal)
- Graphics editor (GIMP)
- Scanning system (Xsane, Peasyscan)
- Printing system (CUPS)
- Video editor (avidemux)
- Photo retouch (Fotoxx)
- CD/DVD/Bluray burner (PBurn)
- Remote connection clients (RDP, VNC, SSH)
- File sharing servers (Samba, FTP, HTTP)
- Text editor - IDE (Geany)
- HTML editor (Seamonkey Composer)
Fatdog ISO is a dual-isohybrid ISO:
- burn it to CD/DVD to make a bootable CD, or
- "dd" it to a USB flash drive to make a bootable flash drive
Fatdog is created by kirk; and is currently maintained by kirk and james.
Site Link
Cyanogen Mod for Android phones
CyanogenMod is an aftermarket firmware for a number of cell phones based on the open-source Android operating system. It offers features not found in the official Android based firmwares of vendors of these cell phones.
Suppose your phone requirement does not met with the newer android os such as 4.0 or greater than this mod allows you to run the newer android os with the oldest minimal hardware requirements.
you must have to root your phone before installing this mod such as Open Recovery to install this cyanogen mod.
For mode details can be found on the website here.
Suppose your phone requirement does not met with the newer android os such as 4.0 or greater than this mod allows you to run the newer android os with the oldest minimal hardware requirements.
you must have to root your phone before installing this mod such as Open Recovery to install this cyanogen mod.
For mode details can be found on the website here.
Subscribe to:
Posts (Atom)