This is a sample program to upload a file and save to databse using hibernate
fileupload.java contains a file field and a submit button
fileupload.jsp
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:form action="addDocument" enctype="multipart/form-data" method="POST">
<table>
<tr>
<td><s:file label="File" name="data"></s:file></td>
</tr>
<tr>
<s:submit type="submit" theme="simple" value="Upload" />
</tr>
</table>
<s:form>
DocumentAction.java
package in.codeglobe.fileupload.action;
public class DocumentAction extends ActionSupport {
private File data;
private String dataContentType;
private String dataFileName;
private Document document = new Document();
public Document getDocument() {
return document;
}
public void setDocument(Document document) {
this.document = document;
}
public File getData() {
return data;
}
public void setData(File data) {
this.data = data;
}
public String getDataContentType() {
return dataContentType;
}
public void setDataContentType(String dataContentType) {
this.dataContentType = dataContentType;
}
public String getDataFileName() {
return dataFileName;
}
public void setDataFileName(String dataFileName) {
this.dataFileName = dataFileName;
}
public String add() {
String result = "view";
try {
FileInputStream fis;
byte[] content = null;
try {
fis = new FileInputStream(data);
content = new byte[fis.available()];
fis.read(content);
fis.close();
} catch (Exception e) {
throw e;
}
document.setData(content);
document.setFileName(dataFileName);
document.setContentType(dataContentType);
/*
u have to write the code to save in to the database
*/
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
The addDocument action in the fileupload.jsp invokes the add method in the DocumentAction class
this method reads the datafrom the uploaded file and store it to the byte array in the
document class.
this is the action mapping for the upload file after successful upload page is redirected to success.jsp
struts.xml
<action name="*Document" method="{1}"
class="in.codeglobe.fileupload.action.DocumentAction">
<result name="view">/success.jsp</result>
</action>
Document.java
package in.codeglobe.fileupload.entity;
public class Document {
private Long documentId;
private String fileName;
private String contentType;
private byte[] data;
public Document() {
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
public Long getDocumentId() {
return documentId;
}
public void setDocumentId(Long documentId) {
this.documentId = documentId;
}
}
success,jsp
File with file name ${dataFileName} is successfully uploaded to database
File type: ${dataContentType}
This is the hibernate configuration
document.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="in.codeglobe.fileupload.entity.Document"
table="DOCUMENT">
<id name="documentId" column="documentId">
<generator class="native" />
</id>
<property name="data">
<column name="data" sql-type="MEDIUMBLOB"></column>
</property>
<property name="fileName" />
<property name="contentType" />
</class>
</hibernate-mapping>
cheapest web development hosting solutions cochin kerala
Welcome to CodeGlobe. CodeGlobe provides free source code, tutorials and latest useful technology news.
Thursday, August 27, 2009
Running ASP.NET Applications in Debian and Ubuntu
Mono is an open-source project providing the necessary software to develop and run .NET client and server applications on Linux, Solaris, Mac OS X, Windows, and Unix. Monodevelop is probably the best IDE for developing .NET applications on Linux. In order to install and use it for development, you will also need the Mono .NET runtime environment installed.
Mono has a fully functional implementation of ASP.NET. This includes full support for ASP.NET Web Forms and Web Services. This essentially means that more or less any ASP.NET application that you have developed using with the .NET Framework will work with MonoASP.NET with Mono you have two options as regards which web server to host your ASP.NET applications that is XSP and Apache.
XSP
XSP is a “light-weight web server” capable of hosting and serving ASP.NET applications. It is written using C#, making extensive use of the classes in the System.Web namespace.XSP web server runs on both the Mono runtime and also on the .NET runtime.
Now we are going to take a look how to install XPS and mono for ASP.NET applications and testing this setupnstall mono in Debian
If you want to install mono in your debian system you need to run the following command
#apt-get install mono mono-gmcs mono-gac mono-utils monodevelop monodoc-browser monodevelop-nunit monodevelop-versioncontrol
You can can see in this screen which will install all the required packages
Install mono in Ubuntu
If you want to install mono in your Debian system you need to run the following command
sudo apt-get install mono mono-gmcs mono-gac mono-utils monodevelop monodoc-browser monodevelop-nunit monodevelop-versioncontrol
Install XSP Web server in Debian
If you want to install ASP.NET2.0 version use the following command
#apt-get install mono-xsp2 mono-xsp2-base asp.net2-examples
If you want to install ASP.NET1.0 version use the following command
#apt-get install mono-xsp mono-xsp-base asp.net-examples
This will install all the required development environment and sample applications
Install XSP Web server in Ubuntu
If you want to install ASP.NET2.0 version use the following command
sudo apt-get install mono-xsp2 mono-xsp2-base asp.net2-examples
If you want to install ASP.NET1.0 version use the following command
sudo apt-get install mono-xsp mono-xsp-base asp.net-examples
This will install all the required development environment and sample applications for ASP.NET
Test ASP.NET Applications
We have already installed sample applications
If you want to run ASP.NET 2.0 application you need to go to /usr/share/asp.net2-demos/ run the following command
#xsp2
This will start the XSP with ASP.Net 2.0 application
xsp2
Listening on port: 8080 (non-secure)
Listening on address: 0.0.0.0
Root directory: /usr/share/asp.net2-demos
Hit Return to stop the server.
Application_Start
Now you need to point your web browser to http://localhost:8080/
If you want to run ASP.NET 1.0 application you need to go to /usr/share/asp.net-demos/ run the following command
#xsp
This will start the XSP with ASP.Net 1.0 application
xsp
Listening on port: 8080 (non-secure)
Listening on address: 0.0.0.0
Root directory: /usr/share/asp.net-demos
Hit Return to stop the server.
Application_Start
Now you need to point your web browser to http://localhost:8080/
Possible errors
If you get the following error when you point http://localhost:8080/
Error Message: HTTP 404. File not found /usr/share/asp.net2-demos/index2.aspx
Solution
You need to copy the index.aspx to index2.aspx
For Debian Users
#cp /usr/share/asp.net2-demos/index.aspx /usr/share/asp.net2-demos/index2.aspx
For Ubuntu Users
sudo cp /usr/share/asp.net2-demos/index.aspx /usr/share/asp.net2-demos/index2.aspx
.net application developers cochin kerala
web IT solutions cochin Kerala
Mono has a fully functional implementation of ASP.NET. This includes full support for ASP.NET Web Forms and Web Services. This essentially means that more or less any ASP.NET application that you have developed using with the .NET Framework will work with MonoASP.NET with Mono you have two options as regards which web server to host your ASP.NET applications that is XSP and Apache.

XSP
XSP is a “light-weight web server” capable of hosting and serving ASP.NET applications. It is written using C#, making extensive use of the classes in the System.Web namespace.XSP web server runs on both the Mono runtime and also on the .NET runtime.
Now we are going to take a look how to install XPS and mono for ASP.NET applications and testing this setupnstall mono in Debian
If you want to install mono in your debian system you need to run the following command
#apt-get install mono mono-gmcs mono-gac mono-utils monodevelop monodoc-browser monodevelop-nunit monodevelop-versioncontrol
You can can see in this screen which will install all the required packages
Install mono in Ubuntu
If you want to install mono in your Debian system you need to run the following command
sudo apt-get install mono mono-gmcs mono-gac mono-utils monodevelop monodoc-browser monodevelop-nunit monodevelop-versioncontrol
Install XSP Web server in Debian
If you want to install ASP.NET2.0 version use the following command
#apt-get install mono-xsp2 mono-xsp2-base asp.net2-examples
If you want to install ASP.NET1.0 version use the following command
#apt-get install mono-xsp mono-xsp-base asp.net-examples
This will install all the required development environment and sample applications
Install XSP Web server in Ubuntu
If you want to install ASP.NET2.0 version use the following command
sudo apt-get install mono-xsp2 mono-xsp2-base asp.net2-examples
If you want to install ASP.NET1.0 version use the following command
sudo apt-get install mono-xsp mono-xsp-base asp.net-examples
This will install all the required development environment and sample applications for ASP.NET
Test ASP.NET Applications
We have already installed sample applications
If you want to run ASP.NET 2.0 application you need to go to /usr/share/asp.net2-demos/ run the following command
#xsp2
This will start the XSP with ASP.Net 2.0 application
xsp2
Listening on port: 8080 (non-secure)
Listening on address: 0.0.0.0
Root directory: /usr/share/asp.net2-demos
Hit Return to stop the server.
Application_Start
Now you need to point your web browser to http://localhost:8080/
If you want to run ASP.NET 1.0 application you need to go to /usr/share/asp.net-demos/ run the following command
#xsp
This will start the XSP with ASP.Net 1.0 application
xsp
Listening on port: 8080 (non-secure)
Listening on address: 0.0.0.0
Root directory: /usr/share/asp.net-demos
Hit Return to stop the server.
Application_Start
Now you need to point your web browser to http://localhost:8080/
Possible errors
If you get the following error when you point http://localhost:8080/
Error Message: HTTP 404. File not found /usr/share/asp.net2-demos/index2.aspx
Solution
You need to copy the index.aspx to index2.aspx
For Debian Users
#cp /usr/share/asp.net2-demos/index.aspx /usr/share/asp.net2-demos/index2.aspx
For Ubuntu Users
sudo cp /usr/share/asp.net2-demos/index.aspx /usr/share/asp.net2-demos/index2.aspx
.net application developers cochin kerala
web IT solutions cochin Kerala
Get Running Process C#
using System.Diagnostics;
ProcessThreadCollection threadlist = theProcess.Threads;
foreach(ProcessThread theThread in threadlist){
Console.WriteLine("Thread ID:{0} Priority: {1} Started: {2}", theThread.Id, theThread.PriorityLevel, theThread.StartTime);
}
ProcessThreadCollection threadlist = theProcess.Threads;
foreach(ProcessThread theThread in threadlist){
Console.WriteLine("Thread ID:{0} Priority: {1} Started: {2}", theThread.Id, theThread.PriorityLevel, theThread.StartTime);
}
Tuesday, August 25, 2009
PixelShots a Mobile Photography blog
An ultimate place for cellphone photography, Digital photography using various MP cell phone cameras
Pixelshots
kerala webdesigns cochin
Send Mail Using JAVA MAIL API
The JavaMail API is a set of abstract APIs that model a mail system. The API provides a platform independent and protocol independent framework to build Java technology based email client applications. The JavaMail API provides facilities for reading and sending email. Service providers implement particular protocols. Several service providers are included with the JavaMail API package; others are available separately. The JavaMail API is implemented as a Java optional package that can be used on JDK 1.4 and later on any operating system. The JavaMail API is also a required part of the Java Platform, Enterprise Edition (Java EE).
You can download Java Mail API from http://java.sun.com/products/javamail/downloads/
An Example program for sending mail using JAVA Mail
------------------------------------------------------------------
Before run the example code please goes through steps given below
1. download java mail API. and add to Classpath
2. Create one Gmail Account ( in this example we use google mail server as server)
3. edit the code "USERNAME = new gmail id" and PASSWORD = "password of new gmail id";
4. edit formAddress and to address.
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
public static final String MAIL_SERVER = "smtp.gmail.com";
public static final String USERNAME = "servermail@gmail.com";
public static final String PASSWORD = "password";
public static void main(String[] args) {
try {
fromAddress = "fromaddress@gmail.com";
String toAddress = "toaddress@gmail.com";
String subject = "This is a test Message";
String message = "Hello Hows u?";
Properties properties = System.getProperties();
properties.put("mail.smtps.host", MAIL_SERVER);
properties.put("mail.smtps.auth", "true");
Session session = Session.getInstance(properties);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddress));
msg.addRecipients(Message.RecipientType.TO, toAddress);
msg.setSubject(subject);
msg.setText(message);
Transport tr = session.getTransport("smtps");
tr.connect(MAIL_SERVER, USERNAME, PASSWORD);
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
} catch (AddressException ex) {
System.out.println(ex.getMessage());
} catch (MessagingException ex) {
System.out.println(ex.getMessage());
}
}
}
webdevelopers webhosting application development-IT solutions Cochin Kerala
You can download Java Mail API from http://java.sun.com/products/javamail/downloads/
An Example program for sending mail using JAVA Mail
------------------------------------------------------------------
Before run the example code please goes through steps given below
1. download java mail API. and add to Classpath
2. Create one Gmail Account ( in this example we use google mail server as server)
3. edit the code "USERNAME = new gmail id" and PASSWORD = "password of new gmail id";
4. edit formAddress and to address.
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
public static final String MAIL_SERVER = "smtp.gmail.com";
public static final String USERNAME = "servermail@gmail.com";
public static final String PASSWORD = "password";
public static void main(String[] args) {
try {
fromAddress = "fromaddress@gmail.com";
String toAddress = "toaddress@gmail.com";
String subject = "This is a test Message";
String message = "Hello Hows u?";
Properties properties = System.getProperties();
properties.put("mail.smtps.host", MAIL_SERVER);
properties.put("mail.smtps.auth", "true");
Session session = Session.getInstance(properties);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddress));
msg.addRecipients(Message.RecipientType.TO, toAddress);
msg.setSubject(subject);
msg.setText(message);
Transport tr = session.getTransport("smtps");
tr.connect(MAIL_SERVER, USERNAME, PASSWORD);
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
} catch (AddressException ex) {
System.out.println(ex.getMessage());
} catch (MessagingException ex) {
System.out.println(ex.getMessage());
}
}
}
webdevelopers webhosting application development-IT solutions Cochin Kerala
Monday, August 24, 2009
Snake game for U in turbo c
# include <stdio.h>
# include <graphics.h>
# include <stdlib.h>
# include <dos.h>
# include <conio.h>
int gdriver=DETECT,gmode,x1=0,y1=0,x2,y2,k=0,c,a,i=0;
int bufx[150],bufy[150],dist=7,delayspeed=100,d;
int rndx,rndy,tail=2,size,dash=0;
int life=5;
int choice;
void randomnumber(void);
void move(int a);
void statusbar(void);
void main()
{
// registerfarbgidriver(EGAVGA_driver_far);
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
size=tail;
cleardevice();
printf("Devlopped By IDEAL BERG");
printf("Enter the speed:: \n<1> for slow <2> for slower <3> for slowest\n<4> for normal\n<5> for fast <6> for faster <7> for fastest");
scanf("%d",&choice);
switch(choice)
{
case 1: delayspeed=250;break;
case 2: delayspeed=200;break;
case 3: delayspeed=160;break;
case 4: delayspeed=90;break;
case 5: delayspeed=60;break;
case 6: delayspeed=40;break;
case 7: delayspeed=20;break;
};
cleardevice();
randomnumber();
bar3d(rndx,rndy,rndx+dist,rndy+dist,0,0);
statusbar();
while((c=getch())!='\033')
{
if (c=='\115') a=1;
if (c=='\113') a=2;
if (c=='\120') a=3;
if (c=='\110') a=4;
dash=0;
move(a);
}
}
void move(int a)
{
void checkcollision(int x1,int y1);
void checkcapture(int x1,int y1);
while(!kbhit())
{
if (!dash)
{
k=k++%size;
i++;
setfillstyle(1,7);
bar3d(x1,y1,x1+dist,y1+dist,0,0);
if(i>=size) // Style start
{
setfillstyle(0,0);
setcolor(0);
bar3d(bufx[k],bufy[k],bufx[k]+dist,bufy[k]+dist,0,0);
bufx[k]=x1;
bufy[k]=y1;
setcolor(15);
checkcapture(x1,y1);
}
else
{
bufx[1]=x1;
bufy[1]=y1;
}
if(a==1) x1=x1+dist;
if(a==2) x1=x1-dist;
if(a==3) y1=y1+dist;
if(a==4) y1=y1-dist;
checkcollision(x1,y1);
setfillstyle(1,14);
bar3d(x1,y1,x1+dist,y1+dist,0,0);
sound(300);
delay(delayspeed);
nosound();
delay(delayspeed);
}
}
}
void checkcollision(int x1,int y1)
{
int i;
for(i=1;i<=size;i++) if((bufx[i]==x1)&&(bufy[i]==y1)) dash=1; if((x1<0)||(x1>=400)||(y1<0)||(y1>400)) dash=1;
if(dash)
{
if(--life<0) exit(0); sound(700); delay(300); nosound(); if(size>25) life++;size=tail;
cleardevice();
}
statusbar();
}
void checkcapture(int x1,int y1)
{
int i;
if((x1==rndx)&&(y1==rndy))
{
size++;
sound(500);
delay(100);
randomnumber();
}
setfillstyle(11,14);
bar3d(rndx,rndy,rndx+dist,rndy+dist,0,0);
}
void statusbar()
{
char s[10];
s[1]=life;
setcolor(15);
rectangle(0,0,400,400);
gotoxy(55,2);
printf("Life: %d size: %d",life,size);
gotoxy(55,5);
printf("Down: ");
putchar(31);
printf("\tUP");
putchar(30);
gotoxy(55,6);
printf("RIGHT :");
putchar(16);
printf("\tLEFT :");
putchar(17);
}
void randomnumber()
{
int i,j;
randomize();
i=random(10000)%40;
i=i*dist;
j=random(10000)%40;
j=j*dist;
rndx=i;
rndy=j;
}
Kerala IT companies - webdevelopment webhosting application development Cochin
# include <graphics.h>
# include <stdlib.h>
# include <dos.h>
# include <conio.h>
int gdriver=DETECT,gmode,x1=0,y1=0,x2,y2,k=0,c,a,i=0;
int bufx[150],bufy[150],dist=7,delayspeed=100,d;
int rndx,rndy,tail=2,size,dash=0;
int life=5;
int choice;
void randomnumber(void);
void move(int a);
void statusbar(void);
void main()
{
// registerfarbgidriver(EGAVGA_driver_far);
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
size=tail;
cleardevice();
printf("Devlopped By IDEAL BERG");
printf("Enter the speed:: \n<1> for slow <2> for slower <3> for slowest\n<4> for normal\n<5> for fast <6> for faster <7> for fastest");
scanf("%d",&choice);
switch(choice)
{
case 1: delayspeed=250;break;
case 2: delayspeed=200;break;
case 3: delayspeed=160;break;
case 4: delayspeed=90;break;
case 5: delayspeed=60;break;
case 6: delayspeed=40;break;
case 7: delayspeed=20;break;
};
cleardevice();
randomnumber();
bar3d(rndx,rndy,rndx+dist,rndy+dist,0,0);
statusbar();
while((c=getch())!='\033')
{
if (c=='\115') a=1;
if (c=='\113') a=2;
if (c=='\120') a=3;
if (c=='\110') a=4;
dash=0;
move(a);
}
}
void move(int a)
{
void checkcollision(int x1,int y1);
void checkcapture(int x1,int y1);
while(!kbhit())
{
if (!dash)
{
k=k++%size;
i++;
setfillstyle(1,7);
bar3d(x1,y1,x1+dist,y1+dist,0,0);
if(i>=size) // Style start
{
setfillstyle(0,0);
setcolor(0);
bar3d(bufx[k],bufy[k],bufx[k]+dist,bufy[k]+dist,0,0);
bufx[k]=x1;
bufy[k]=y1;
setcolor(15);
checkcapture(x1,y1);
}
else
{
bufx[1]=x1;
bufy[1]=y1;
}
if(a==1) x1=x1+dist;
if(a==2) x1=x1-dist;
if(a==3) y1=y1+dist;
if(a==4) y1=y1-dist;
checkcollision(x1,y1);
setfillstyle(1,14);
bar3d(x1,y1,x1+dist,y1+dist,0,0);
sound(300);
delay(delayspeed);
nosound();
delay(delayspeed);
}
}
}
void checkcollision(int x1,int y1)
{
int i;
for(i=1;i<=size;i++) if((bufx[i]==x1)&&(bufy[i]==y1)) dash=1; if((x1<0)||(x1>=400)||(y1<0)||(y1>400)) dash=1;
if(dash)
{
if(--life<0) exit(0); sound(700); delay(300); nosound(); if(size>25) life++;size=tail;
cleardevice();
}
statusbar();
}
void checkcapture(int x1,int y1)
{
int i;
if((x1==rndx)&&(y1==rndy))
{
size++;
sound(500);
delay(100);
randomnumber();
}
setfillstyle(11,14);
bar3d(rndx,rndy,rndx+dist,rndy+dist,0,0);
}
void statusbar()
{
char s[10];
s[1]=life;
setcolor(15);
rectangle(0,0,400,400);
gotoxy(55,2);
printf("Life: %d size: %d",life,size);
gotoxy(55,5);
printf("Down: ");
putchar(31);
printf("\tUP");
putchar(30);
gotoxy(55,6);
printf("RIGHT :");
putchar(16);
printf("\tLEFT :");
putchar(17);
}
void randomnumber()
{
int i,j;
randomize();
i=random(10000)%40;
i=i*dist;
j=random(10000)%40;
j=j*dist;
rndx=i;
rndy=j;
}
Kerala IT companies - webdevelopment webhosting application development Cochin
Monday, August 17, 2009
"Setup did not find any hard disk drives" during Windows XP Installation on Dell Laptops

Are you experience trouble installing Windows XP in your Dell Laptop?
Before you install XP, you must first configure a setting in BIOS else XP CD will not detect your hard disk
In BIOS:
Onboard Devices -> Flash Cache Module -> Set Off
Onboard Devices -> SATA Operation -> Set ATA
Ok, you can now proceed with installing Windows XP
Subscribe to:
Posts (Atom)