Archive for October, 2008|Monthly archive page

How to change windows Logon & Logoff sound

goto control panel -> sounds and audio devices..
select sound tab from that dialogue box…
now select windows logon or logoff from program events and browse to set ur desire sound, the format of the file can only be wave.


Creating One click Shutdown icon:

Right-click On the desktop, and go to New, then to Shortcut. You will now see a pop-up window instructing you to enter a command line path.
Just type:-
SHUTDOWN -s -t 01
click next & then give it any name.
Now if u want to shutdown your system just click it..
your system will get shutdown..

You can also make a timer for your system from this
for example u want that your system would get shutdown in 1 hour then create a shortcut and type:-
SHUTDOWN -s -t 3600
now if you click it. your system will get shutdown in 1 hour.
Remember the time is in seconds.

How to display your Flash files in Html:-

The easiest way to embed Flash in a website, with a single embed code. Create a Flash File named file.swf locate it in the same directory as the HTML page.

Write the following code in the html.

<object width=”300″ height=”200″>
<param name=”movie” value=”file.swf”>

U Need to Have a Flash Plugin Installed if u want to see ur flash files. A broken icon will appear on the Web page if the u don’t have the Flash plug-in installed.

In the above code i have used both an tag and an <object> tag because the <object> tag is recognized by Internet Explorer, and Netscape recognizes the tag.

The other Parameters that you can use are:-

*  bgcolor (#rrggbb): set the SWF background color using a hexadecimal value.

*  flashvars (variables): the variables placed here will be loaded in the SWF.

*  The JW Player extensively uses those. menu (true, false): set this to false to hide most of the rightclick menu.

*  The allowscriptaccess and allowfullscreen parameters tell the browser the SWF can both communicate with external scripts (and link to external pages) and use the new fullscreen mode.

How to upload & download a file in Struts framework

Hello friends, I worked on a project to create a website for jobs seeker & jobs provider using Struts framework which required file uploading & downloading of Resume.

Before I explain you the code, let me give u brief introduction of struts framework first:-

Struts is a free open-source framework for creating Servlet/JSP based web applications based on Model-View-Controller (MVC) architecture. The Model represents the business or database code, the View represents the page design code, and the Controller represents the navigational code. The Struts framework is designed to help developers create web applications that utilize a MVC architecture.

you can use any IDE to develop your struts application like NetBeans, Eclipse or Weblogic.

First of all create a jsp named FileUpload

<title>Struts File Upload</title>
<html:form action=”/fileupload” method=”post” enctype=”multipart/form-data”>
<font size=”5″>File Upload on Server</font>
<font color=”red”><html:errors/></font>
File Name
<html:file property=”theFile”/>
<html:submit>Upload File</html:submit>

Now since we have used html tag library so you will have to add
taglib uri of html in case of Netbeans.

This jsp will have file type property from where u can browse the file on clicking submit the action fileupload will be called.

Now create a Bean package named beans & then create a class bean named StrutsUploadAndSaveForm which will extend ActionForm class

package beans;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
public class StrutsUploadAndSaveForm extends ActionForm
private FormFile theFile;

public FormFile getTheFile() {
return theFile;

public void setTheFile(FormFile theFile) {
this.theFile = theFile;

in the above code getTheFile function Returns the File &
setTheFile function set the file whose parameters are passes.

Now create action package named action and create a action class named StrutsUploadAndSaveAction which extends Action class

package action;
import bean.StrutsUploadAndSaveForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
public class StrutsUploadAndSaveAction extends Action
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request, HttpServletResponse response) throws Exception
StrutsUploadAndSaveForm myForm = (StrutsUploadAndSaveForm)form;
// Process the FormFile
FormFile myFile = myForm.getTheFile();
String contentType = myFile.getContentType();
//Get the file name
String fileName = myFile.getFileName();
byte[] fileData = myFile.getFileData();
//Get the servers upload directory real path name
String filePath = getServlet().getServletContext().getRealPath(“/”) +”upload”;
/* Save file on the server */
System.out.println(“Server path:” +filePath);
//Create file
File fileToCreate = new File(filePath, fileName);
//If file does not exists create file
FileOutputStream fileOutStream = new FileOutputStream(fileToCreate);


//Set file name to the request object

return mapping.findForward(“success”);


/* This action class first takes the file which is set in the bean. then its actual path is stored in the variable filepath.
then if the filepath is not empty, a new file with same name is created inside realpath of servlet or jsp/upload
if the filepath is empty than fileOutStream is flushed.
& in the end name of the file is set in the request scope such that the same file can be downloaded latter.

Now enter the Code in Struts Config such that their is right mapping of the code.

<form-bean name=”FileUpload” type=”beans.StrutsUploadAndSaveForm”/>



<action path=”/fileUpload” type=”action.StrutsUploadAndSaveAction” name=”FileUpload” scope=”request” validate=”true” input=”/FileUploadAndSave.jsp”>

<forward name=”success” path=”/downloadfile.jsp”/>




Now create a jsp named downloadfile.jsp

String fileName=(String)request.getAttribute(“fileName”);


<p align=”center”><font size=”5″ color=”#000080″>File Successfully Received</font></p>
<p align=”center”><a href=”upload/<%=fileName%>”>Click here to download</a></p>


How to send mail with Action Mailer in Ruby on Rails

Action Mailer is the Rails component that enables applications to send and receive e-mail.

Create a New Project emails.

D:\ruby\> rails emails
this requires framework i suggest you to use Instant Rails 2.0 framework.
just by writting this command all controllers, views, models & helpers etc Automatically gets created.

Action Mailer – ConfigurationFollowing

Go into config folder of your emails project and open environment.rb file and add the following lines at the bottom of this file

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {:address => “”,
:port => 25,
:domain => “”,
:authentication => :login,
:user_name => “username”,
:password => “password”,



Remember you should have account on Ruby On Rails Server.
Replace each hash value with proper settings for your Simple Mail Transfer Protocol (SMTP) server. You don’t need to change port number 25 and authentication type if you are using standard SMTP server

Now the Next step is to create mailer

Generate a mailer
D:\ruby\> cd emails
D:\ruby\emails> ruby script/generate mailer Emailer

This will create a file emailer.rb in app\models directory.Check the content of this file is as follows
class Emailer < ActionMailer::Base
Create One Method as follows:-
class Emailer < ActionMailer::Base
def contact(recipient, subject, message, sent_at =
@subject = subject
@recipients = recipient
@from = ‘’
@sent_on = sent_at
@body[“title”] = ‘This is title’
@body[“email”] = ‘’
@body[“message”] = message

The contact method has four parameters a recipient, subject, message and a sent_at, which defines when the e-mail is sent.
@subject defines the e-mail subject.
@body is a Ruby hash that contains values with which you can populate the mail template. You created three key-value pairs: title, email, and message
@recipients is a list of the people to whom the message is being sent.
@from defines who the e-mail is from.
@sent_on takes the sent_at parameter and sets the timestamp of the e-mail

Now we will create a mailer template which is just text with standard Rails <%= %> placeholders scattered throughout

Put following code in app/views/contact.html.erb
(if you are using Instant Rails 2.0 or more)

or put the following code in app/views/contact.rhtml (if you are using Instant Rails version 1.7)

<%= @message %>

Now we had to create a controller for this application as follows
D:\ruby\emails> ruby script/generate controller Emailer

class EmailerController < ApplicationController
def sendmail
email = @params[“email”]
recipient = email[“recipient”]
subject = email[“subject”]
message = email[“message”]
Emailer.deliver_contact(recipient, subject, message)
return if request.xhr?
render :text => ‘Message sent successfully’

To deliver e-mail using the mailer’s contact method, you have to add deliver_ to the beginning of the method name. You add a return if request.xhr? so that you can escape to Rails Java Script (RJS) if the browser does not support JavaScript and then tell the method to render a text message.

Now The Task Is Almost done Except for creating the view part for the user.

Now let’s define our view in app\views\emails\index.html.erb
<head><title>Send Mail</title></head>
<h1>Send Email</h1>
<% form_tag ({:action => “sendmail”},{ :method=>”post”}) do-%>
<label for=”email_subject”>Subject</label>:
<%= text_field ’email’, ‘subject’ %>
<label for=”email_recipient”>Recipient</label>:
<%= text_field ’email’, ‘recipient’ %>
</p> <p><label for=”email_message”>Message</label><br/>
<%= text_area ’email’, ‘message’ %></p>
<%= submit_tag “Send” %>
<% end-%></body>
This will send your message and will display text message that “Message sent successfully”
The modified version of this Application is working in

Queries Are Welcomed