SpringEasytoLearn Adviser

http://www.mkyong.com/

Advertisements
Posted in Tutorial Links | Leave a comment

Disable RightClick Mouse and Disable Print Screen Key…Using JavaScript

ImageImage

 How To Block Print Screen As well As Mouse functionalities With Java Script

<html>
<head>

 <script language=”Javascript1.2″>
am = “This function is disabled!”;
bV  = parseInt(navigator.appVersion)
bNS = navigator.appName==”Netscape”
bIE = navigator.appName==”Microsoft Internet Explorer”
function check(e) {
   if (bNS && e.which > 1){
      alert(am)
      return false
   } else if (bIE && (event.button >1)) {
     alert(am)
     return false;
   }
}
document.onmousedown = check;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (bNS && bV<5) window.onmousedown = check;
</script>
</head>
<!–what i mention in body tag that the way to impliment inline java script –>
<body onload=setInterval(“window.clipboardData.setData(‘text’,”)”,2) oncontextmenu=”return false” onselectstart=”return false” >
This Document is Protected with RightClick & left Click &Print Screen  with Alerts!!!!!!!!!!!!!!!
</body>
</html>

With Regards ,

K.RAJA SEKHAR REDDY (Software Developer)

Posted in JavaScrpit | Tagged | 3 Comments

Restrict Copy Paste in Webpages with java Script

Image

Easy To Implement Try  This

<html>
<head>
<script type=”text/javascript”>
function start(){
block = setInterval(“window.clipboardData.setData(‘text’,”)”,20);
}
function stop(){
clearInterval(block);
}
</script>
</head>

<body onload=”start();”>
YOU TRY TO COPY AND PASTE THIS SCREEN, AND ALL THE ACTIVE SCREENS
<input type=”button” onclick=”stop();” value=”stop blocking copy/paste!”>

</body>
</html>

With Regard’s

K.RAJA SEKHAR REDDY(RAJ9992)

Software Developer

Posted in JavaScrpit | Tagged | Leave a comment

Java Code to Send an Email With Time Scheduling

Image

Java Code To  Send a Mail  With   a Time Intervals

5 steps u have to Fallow

1.Create a GMailServer.java

package com.java.mail;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class GMailServer extends javax.mail.Authenticator
{
private String mailhost =”smtp.gmail.com”; ; //”smtp.mail.yahoo.com”; //”smtp.gmail.com”;
private String user;
private String password;
private Session session;

public GMailServer(String user, String password) {
this.user = user;
this.password = password;

Properties props = new Properties();
props.setProperty(“mail.transport.protocol”, “smtp”);
props.setProperty(“mail.smtp.host”, mailhost);
props.put(“mail.smtp.auth”, “true”);
props.put(“mail.smtp.port”, “465”);
props.put(“mail.smtp.socketFactory.port”, “465”);
props.put(“mail.smtp.socketFactory.class”,”javax.net.ssl.SSLSocketFactory”);
props.put(“mail.smtp.starttls.enable”,”true”);
props.put(“mail.smtp.debug”, “true”);
props.put(“mail.smtp.socketFactory.fallback”, “false”);
props.setProperty(“mail.smtp.quitwait”, “false”);

session = Session.getDefaultInstance(props, this);
}

protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(user, password);
}

public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception
{
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), “text/plain”));
message.setSender(new InternetAddress(sender));
message.setSubject(subject);
message.setDataHandler(handler);
if (recipients.indexOf(‘,’) > 0)
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
else
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
Transport.send(message);
}

public class ByteArrayDataSource implements DataSource {
private byte[] data;
private String type;

public ByteArrayDataSource(byte[] data, String type) {
super();
this.data = data;
this.type = type;
}

public ByteArrayDataSource(byte[] data) {
super();
this.data = data;
}

public void setType(String type) {
this.type = type;
}

public String getContentType() {
if (type == null)
return “application/octet-stream”;
else
return type;
}

public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(data);
}

public String getName() {
return “ByteArrayDataSource”;
}

public OutputStream getOutputStream() throws IOException {
throw new IOException(“Not Supported”);
}
}
}

                                            2. Create DBScheduler.java

package com.java.mail;

import java.util.Timer;
import JavaConstants.Constants;

public class DBScheduler
{

public void callScheduler() throws Exception
{

System.out.println(“Scheduler Starterd…”);
ReadPropertiesFile.readConfig();
Timer timer = new Timer();

timer.scheduleAtFixedRate(new Testing(), getTimePrecision(Constants.delay), getTimePrecision(Constants.timetoquery));

}

public long getTimePrecision(String value) throws Exception
{
long  l = 0;
String val=””;
try
{
if(value.endsWith(“d”) || value.endsWith(“D”))
{
val  = value.substring(0,value.length()-1);
l = Long.parseLong(val) * 24 * 60 * 60 * 1000;
}

else if(value.endsWith(“h”) || value.endsWith(“H”))
{

val  = value.substring(0,value.length()-1);
l = Long.parseLong(val) * 60 * 60 * 1000;

}
else if(value.endsWith(“m”) || value.endsWith(“M”))
{
val  = value.substring(0,value.length()-1);
l = Long.parseLong(val) * 60 * 1000;
}
else if(value.endsWith(“s”) || value.endsWith(“S”))
{

val  = value.substring(0,value.length()-1);
l = Long.parseLong(val) * 1000;
}
else
{

l = Long.parseLong(value);
}

}
catch(Exception e)
{

throw new Exception(e);
}

return l;
}
public static void main(String a[]) throws Exception
{
DBScheduler dbs = new DBScheduler();
dbs.callScheduler();
}

}

3.Create Testing.java

package com.java.mail;
import java.util.TimerTask;
import JavaConstants.Constants;

public class Testing extends TimerTask
{

public void run()
{
GMailServer sender = new GMailServer(Constants.setFrom, Constants.setPassword);
try {
sender.sendMail(“Subject”,”This is RAJ”,Constants.setFrom,Constants.emailTO);
}
catch (Exception e) {
e.printStackTrace();
}

System.out.println(“Email Sent Succesfully…”);

}
}

                                        4.Create ReadPropertiesFile.java

package com.java.mail;
import java.io.FileInputStream;
import java.util.Properties;
import JavaConstants.Constants;

public class ReadPropertiesFile
{
public  static void readConfig() throws Exception
{
try
{

Properties pro = new Properties();
String path = System.getProperty(“user.dir”)+”/java_Props.properties”;
pro.load(new FileInputStream(path));
Constants.delay = pro.getProperty(“delay”);
Constants.timetoquery = pro.getProperty(“timetoquery”);
Constants.setFrom = pro.getProperty(“setFrom”);
Constants.setPassword = pro.getProperty(“setPassword”);
Constants.emailTO = pro.getProperty(“emailTO”);

}
catch(Exception e)
{
throw new Exception(e);
}

}

}

                                  5. Create  Constant.java in another package

package JavaConstants;

public class Constants
{
public static String delay;
public static String timetoquery;
public static String setFrom;
public static String setPassword;
public static String emailTO;
}

6.Configuration File is here Just Named it as java_props.properties

setFrom = abc@gmail.com
setPassword = XXXXXXX

#repeat for every 10 seconds
timetoquery = 1h

#start after 2seconds for first time..
delay = 2s

emailTO = reciever@gmail.com

At last add these Three jar files into ur project

  activation.jar,common-email.jar,mail.jar

Note: Never Disturb GMailServer.java  Run only DbScheduler.java

While Executing this project u can send a Mails With time Span How Ever U like

I hope u Understand the scenario Very Well any Doudbts are else any clarifications just send Me feed Back…………….

With Regard’s

K.RAJA SEKHAR REDDY(RAJ9992)
Software Engineer

Posted in Java Codes Examples | Tagged | 1 Comment

BelogicInspiration

Be Yourself @ Belogic :

Image

Don’t wish to be normal. Wish to be yourself. To the hilt. Find out what you’re best at, and develop it, and hopscotch your weaknesses. Wish to be great at whatever you are. Lois McMaster Bujold, Labyrinth.

Posted in Uncategorized | Tagged | Leave a comment