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.

Advertisements

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.

<html>
<body>
<center>
<object width=”300″ height=”200″>
<param name=”movie” value=”file.swf”>
http://file.swf
</object
</center>
</body>
</html>

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

<html:html>
<head>
<title>Struts File Upload</title>
<html:base/>
</head>
<body>
<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”/>
<center>
<html:submit>Upload File</html:submit>
</center>
</html:form>
</body>
</html:html>

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;
import java.io.*;
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 */
if(!fileName.equals(“”))
{
System.out.println(“Server path:” +filePath);
//Create file
File fileToCreate = new File(filePath, fileName);
//If file does not exists create file
if(!fileToCreate.exists())
{
FileOutputStream fileOutStream = new FileOutputStream(fileToCreate);
fileOutStream.write(myFile.getFileData());
fileOutStream.flush();
fileOutStream.close();
}

 

}
//Set file name to the request object
request.setAttribute(“fileName”,fileName);

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.

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


</form-beans>

<action-mappings>

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

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

</action>

</action-mappings>

</struts-config>

Now create a jsp named downloadfile.jsp

<html>
<head>
<title>
Success</title>
</head>
<body>
<%
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>
</body>

</html>

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 => “kunal.rubypython.playground.net”,
:port => 25,
:domain => “rubypython.playground.net”,
: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
end
Create One Method as follows:-
class Emailer < ActionMailer::Base
def contact(recipient, subject, message, sent_at = Time.now)
@subject = subject
@recipients = recipient
@from = ‘no-reply@yourdomain.com’
@sent_on = sent_at
@body[“title”] = ‘This is title’
@body[“email”] = ‘sender@yourdomain.com’
@body[“message”] = message
end
end

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’
end
end

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
<html>
<head><title>Send Mail</title></head>
<body>
<h1>Send Email</h1>
<% form_tag ({:action => “sendmail”},{ :method=>”post”}) do-%>
<p>
<label for=”email_subject”>Subject</label>:
<%= text_field ’email’, ‘subject’ %>
</p>
<p>
<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>
</html>
This will send your message and will display text message that “Message sent successfully”
The modified version of this Application is working in www.skid.org.in/emailaddr

Queries Are Welcomed