tag:blogger.com,1999:blog-67364270738111098162024-02-19T00:04:11.086-08:00Information for AllSriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-6736427073811109816.post-55505705422069976282011-09-24T04:00:00.000-07:002011-09-24T04:01:24.129-07:00Unicode character appear as Question Mark or JSP not Support Language Translation<div dir="ltr" style="text-align: left;" trbidi="on">Nowadays most of the application are supposed to support foreign Language for that we need to create properties file.<br />
In the properties file we translate each and every word and save them using key value pair.<br />
Example file:<br />
<b>languageTranslation_ru.properties</b><br />
<pre class="brush: java;">name = имя
password = пароль
submit = представлять
signIn = Войти приложений
</pre><br />
Either use Unicode converter or directly place the translated value in your properties file. You set it up correctly and running your application,<br />
<br />
Surprisingly you are getting question mark "???" in unicode converted place like below screen shot. <br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0p9ATT94ufwwr1EhD7khm_4uPny0F5HUkXR_VurM0CuHH73phW3g_OfaeMnZCQZch-1Oc_z51Cfi4qV4UmO8NVOXpfuRxvRytWWwwoqUULivR0pbe_MKUXmZCk55UT5PboCgbsstRiyA/s1600/LoginApp+with+Question.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="153" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0p9ATT94ufwwr1EhD7khm_4uPny0F5HUkXR_VurM0CuHH73phW3g_OfaeMnZCQZch-1Oc_z51Cfi4qV4UmO8NVOXpfuRxvRytWWwwoqUULivR0pbe_MKUXmZCk55UT5PboCgbsstRiyA/s320/LoginApp+with+Question.jpg" width="320" /></a></div>Everything you did correctly, but why its not working. In your jsp page please check whether you included below attribute.<br />
<pre class="brush: java;"><%@ page contentType="text/html; charset=UTF-8"%></pre>If not include it and you will get expected output. Check below screen shot for actual result<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibw83LDrYCTX5jT1dtJZz1J08WoDfCLt_LMhahB8JQDVs-jn_7KjDO6iXFhXJA6FGLdd86xCbZnhcuOqRan3RlGriVxvCSP6SmIHpjsCWgab5jkPY5XAjtmawzHD8BuXvWtJEpLmJ4pxI/s1600/LangTrans.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibw83LDrYCTX5jT1dtJZz1J08WoDfCLt_LMhahB8JQDVs-jn_7KjDO6iXFhXJA6FGLdd86xCbZnhcuOqRan3RlGriVxvCSP6SmIHpjsCWgab5jkPY5XAjtmawzHD8BuXvWtJEpLmJ4pxI/s1600/LangTrans.jpg" /></a></div><br />
</div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com10tag:blogger.com,1999:blog-6736427073811109816.post-10614808199219406842011-08-06T02:31:00.000-07:002011-08-06T02:40:09.789-07:00How to Run Multiple IE Version in One Machine<div dir="ltr" style="text-align: left;" trbidi="on">As a Developer, We need to test our application in all IE version. In some IE version scroll bar will appear in some others it wont appear. Sadly it behave strange in IE6 version. Its not possible to install all IE version in one machine. If you uninstall your higher IE version, you can get default version i.e IE6 version, but its not possible to install and uninstall all the time.<br />
<br />
Don't scratch your head ???<br />
<br />
Here is the possible way to get all IE version in one machine.<br />
Most of you may heard about IE Tester, some of them may not come across this tool.<br />
If you guys fall in second category just go to their <a href="http://www.my-debugbar.com/wiki/IETester/HomePage" rel="nofollow"><b>IE Tester Home page</b></a> and download the software.<br />
For those who falls under first category just share your views here.<br />
And you can see the screen shot of IE tester home page in this post.<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0egdtiz6ZxfK0JmOghP3cjQ-xQ1DKmnYWiMZkqBwMej0KgA-zoiLDiY0YDInlUuKVdU9N3t0M5Zb3NFbrh2jIa8qyvn3pgbtZrzSK1jZqAV1GzicxH_t1Nt-PcfLPVRJHYC4kAteEEb0/s1600/All+IE+versions.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="71" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0egdtiz6ZxfK0JmOghP3cjQ-xQ1DKmnYWiMZkqBwMej0KgA-zoiLDiY0YDInlUuKVdU9N3t0M5Zb3NFbrh2jIa8qyvn3pgbtZrzSK1jZqAV1GzicxH_t1Nt-PcfLPVRJHYC4kAteEEb0/s320/All+IE+versions.jpg" width="320" /></a><br />
<br />
<br />
<br />
<br />
<br />
I can able to hear your mind voice.<br />
Hey man who want IETester or out dated version say IE5.5 and IE6. I am running higher version of IE for example IE9, I want to test my application in IE7 or IE8 version.<br />
Do you have any idea??<br />
<br />
If you have above mentioned query in your mind, Yes its possible is my answer.<br />
No need to install any other software or tool to run all IE version except IE6 in one machine.<br />
<br />
Open your IE browser, press F12 or follow the below instruction<br />
Go to tools--> click Developer tools <br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgptNKwA4WCKfFHz7yuI9vQwl3rUyUp0dYQJEPrNpmxnv11UgXAUFqOk6LG0xpHgbFs0IKz9DnlGi8qaSgHz8Wji66jTUbM7HV_FdFq70SXjlAKSYvTG1ZR-i4apKZYXc4JgwF1PZFhxrM/s1600/Developer+Tools.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgptNKwA4WCKfFHz7yuI9vQwl3rUyUp0dYQJEPrNpmxnv11UgXAUFqOk6LG0xpHgbFs0IKz9DnlGi8qaSgHz8Wji66jTUbM7HV_FdFq70SXjlAKSYvTG1ZR-i4apKZYXc4JgwF1PZFhxrM/s1600/Developer+Tools.jpg" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
It will open one window, in that window you can choose your preferred version by following this step click browser mode-->in the list select your preferred version.<br />
For example currently I am running IE9 version in my machine, but I want to test my application in IE7 or IE8.I will choose my preferred version as IE7 or IE8 in the list.<br />
So it will change the opened tab to selected version.<br />
Check below screen shot.<br />
<div class="separator" style="clear: both; text-align: center;"></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUiN5z_DaCNtivx719VR0rtzKmHrNJm4zSBGpAbTf5uvalzkexz8tGb4tjbEGk4_YrIlKmjYxSFYZzhpVsRzguW2OO7oos-ULrfk81vlGS7NF-lfPZyWButYFs_4gJTssJIj8SA8T8GQk/s1600/BrowserMode.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="70" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUiN5z_DaCNtivx719VR0rtzKmHrNJm4zSBGpAbTf5uvalzkexz8tGb4tjbEGk4_YrIlKmjYxSFYZzhpVsRzguW2OO7oos-ULrfk81vlGS7NF-lfPZyWButYFs_4gJTssJIj8SA8T8GQk/s320/BrowserMode.jpg" width="320" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
Try it and share your comments...</div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com1tag:blogger.com,1999:blog-6736427073811109816.post-55985569728114019522011-04-21T02:24:00.000-07:002011-06-26T08:41:01.859-07:00Get client width to fix 800x 600 resolution problem in IE and Mozilla using Javascript<div dir="ltr" style="text-align: left;" trbidi="on"> For last couple of weeks, one bug killing me. i.e., the page is not rendering properly in 800x600 resolution.<br />
Well,while assigning the defect I thought it will be so easy to fix and I thought nowadays who cares about that 800x600 resolution problem, but still some freaks are living with that 800x600 resolution.<br />
Let me share the experience/information to fix the defect using javascript. Though I found solution using css, but it not helped me to fix the defect.<br />
Later I decided to fix the defect using javascript and the code as follows,<br />
<pre class="brush: java;">function windowWrapper() {
var cliRes = screen.width;
var cliHeight = document.documentElement.clientHeight;
if(cliRes<=800) {
var newHeight = cliHeight-60;
document.getElementById("wrapping").style.height = newHeight+"px";
document.getElementById("wrapping").style.overflow ="auto";
}
}
</pre> Have you noticed, I have used wrapping inside getElementById. place the id wherever you want to reduce size of the screen in 800x600 resolution. <br />
<pre class="brush: java;"><b id="wrapping" ody=""> </b> //used to reduce the body screen size.
<div id="wrapping"></div>//reduce div container size.
</pre>Let me know how it was worked for you and waiting for your comments.</div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com0tag:blogger.com,1999:blog-6736427073811109816.post-16943259479329426542011-03-11T03:44:00.000-08:002011-03-18T04:54:51.222-07:00Remove dot infront of actionerror and actionmessage in Struts2<div dir="ltr" style="text-align: left;" trbidi="on">You can see the dot symbol infront of actionError and actionMessages while displaying your result in jsp page.<br />
<br />
This is because of placing <s:actionerror /> and <s:actionmessages /> directly into your jsp page.<br />
Actionerror and Actionmessage displays result in un-ordered list format.<br />
Your Error or Message in the following format<br />
<br />
1) . Action Error <br />
2) . Action Message<br />
<br />
Inorder to remove the dot symbol place the <s:actionerror> and <s:actionmessage> inside <s:if> condition<br />
<br />
<pre class="brush: java;"><s:if test="hasActionErrors()">
<div class="errors"><s:actionerror>
</s:actionerror></div></s:if>
</pre><br />
<pre class="brush: java;"><s:if test="hasActionMessages()">
<div class="messages"><s:actionmessage>
</s:actionmessage></div></s:if>
</pre>div class="errors" and div class="messages" are not mandatory.<br />
Both are css classes.<br />
Dot symbol will get removed and you will get the expected result.<br />
<br />
For more java programming click this <a href="http://periodicupdates.blogspot.com/search/label/Programming" style="color: red;">Link.</a><br />
Do post your comments </div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com3tag:blogger.com,1999:blog-6736427073811109816.post-58264542767039885232011-02-15T00:24:00.000-08:002011-02-16T21:53:59.538-08:00Send Mail in specific time Interval using Java<div dir="ltr" style="text-align: left;" trbidi="on">The following jar files required to send mail using java program.<br />
1)Activation.jar<br />
2)Mail.jar<br />
Click this <a href="https://sites.google.com/site/ramsriiq/jarfiles.zip?attredirects=0&d=1"><span style="color: red;">Link</span></a> to download the jar file.<br />
Okay you have downloaded the jar files and placed the same in classpath.<br />
<br />
Lets discuss the program step by step.<br />
There are two options mentioned in this program.Single and multiple<br />
While running program it will ask input from the user single or multiple.<br />
If the user gives single as input the mail will send only once.The program get executes after the timedelay specified in the program.Here we specified as 1000milliseconds.<br />
<br />
If the user pass multiple as input then the program send the mail multiple times with time interval as 10000milliseconds<br />
<pre class="brush: java;">import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Timer;
import java.util.TimerTask;
public class sendMailUsingTimeInterval{
public static void main(String[] args) throws IOException{
int delayInMilliSec= 1000; //in milli seconds.
int delayBetweenExec = 10000;//in milli seconds
Timer timer = new Timer();
System.out.println("Please enter \'Single\' or \'Multiple\')?");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String ans = in.readLine();
if (ans.equalsIgnoreCase("Single")){
timer.schedule(new TimerTask(){
public void run(){
SendMailUsingAuthentication send = new SendMailUsingAuthentication();
try {
send.sendingDetails();
} catch (Exception e) {
System.out.println("in catch block:::");
e.printStackTrace();
}
System.out.println("Single time selected ***");
}
},delayInMilliSec);
}
else if(ans.equalsIgnoreCase("Multiple")){
timer.schedule(new TimerTask(){
public void run(){
SendMailUsingAuthentication send = new SendMailUsingAuthentication();
try {
send.sendingDetails();
} catch (Exception e) {
System.out.println("in catch block:::");
e.printStackTrace();
}
System.out.println("Multiple time selected ****");
}
},delayInMilliSec,delayBetweenExec);
}
else{
System.out.println("Pass single or multiple as input ***");
System.exit(0);
}
}
}
</pre>In above program you can see the method sendingDetails get called.<br />
The sendingDetails method contain the information about the host,port,from user,to user and content.Make sure your local machine machine has internet facility then give host as localhost else give the ip address of the machine.<br />
Generally the port number is 25.<br />
Then you know the from address,to mail address and the mail content also.<br />
pass all the information.<br />
sendingDetails method now invoke the mailSending() method in the same program.<br />
In mailSending method set all valuse to message.<br />
<pre class="brush: java;">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 SendMailUsingAuthentication {
public void mailSending(String smtpHost, int smtp_Port,
String from, String to,
String subject, String content)
throws AddressException, MessagingException {
// Create a mail session
java.util.Properties props = new java.util.Properties();
String smtpPort = Integer.toString(smtp_Port);
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", smtpPort);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));//set from mailId here.
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));//set to mailId here.
msg.setRecipient(Message.RecipientType.CC,new InternetAddress(to));//set cc mailId here.
msg.setSubject(subject);//mail Subject
msg.setContent(content,"text/plain");//mail content in plain format
/*
* To send mail in HTML format disable the
* above content and enable the below one
*/
// msg.setContent("<h1>HTML TYPE MESSAGE</h1>","text/html");//mail Type.It may be plain or html whatever.
/*
* In below I have set the mail sent date as previous date.
* Default it set present date as sent date.
* you can change this as your wish.
* If you want to enable for previous date.just uncomment the below code
*/
/*Calendar origDay = Calendar.getInstance();
System.out.println ("Original Date: " + origDay.getTime());
Calendar prevDay = (Calendar) origDay.clone();
prevDay.add (Calendar.DAY_OF_YEAR, -1);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
msg.setSentDate(prevDay.getTime());*/
String mailHost= "urmail.host.com";//mailHost for your mail provider.For gmail smtp.gmail.com
String userName = "from";//userName for an E-mail provider.
String password = "password";//password for the same.
Transport tr = session.getTransport("smtp");
tr.connect(mailHost,userName,password);
System.out.println("whether connection established***"+tr.isConnected());
msg.saveChanges();
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
System.out.println("Message sent OK.");
}
public void sendingDetails() throws Exception {
mailSending("localhost", 25, "from@gmail.com", "to@gmail.com",
"Sriram", "Test mail."+"\n"+"\n"+"Cheers,"+"\n"+"Sriram.V");
}
}
</pre>Read the comments in the program for more clarification.<br />
Here we send the mail by using Transport.<br />
Transport opens the connection and it connects to mail host.<br />
After the Connection open we are going to send mail using tr.sendMessage()<br />
Once the mail has been successfully send the connection is get closed by calling tr.close()<br />
<br />
Possible execptions <br />
<b><u>AuthenticationFailedException:</u></b><br />
Check the user name and password given in the program to connect to the Transport.<br />
<pre class="brush: java;">javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at javax.mail.Service.connect(Service.java:156)
at sriram.tutorial.javapgm.SendMailUsingAuthentication.mailSending(SendMailUsingAuthentication.java:61)
at sriram.tutorial.javapgm.SendMailUsingAuthentication.sendingDetails(SendMailUsingAuthentication.java:70)
at sriram.tutorial.javapgm.sendMailUsingTimeInterval$1.run(example.java:25)
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)
</pre><b><u>MessagingException:</u></b><br />
Check the mailHost.It attempt to connect to the given host but failed to connet.<br />
<pre class="brush: java;">javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at sriram.tutorial.javapgm.SendMailUsingAuthentication.mailSending(SendMailUsingAuthentication.java:61)
at sriram.tutorial.javapgm.SendMailUsingAuthentication.sendingDetails(SendMailUsingAuthentication.java:70)
at sriram.tutorial.javapgm.sendMailUsingTimeInterval$1.run(example.java:25)
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
... 9 more</pre><div class="brush: java;"></div>Want to <span style="color: magenta;">Send SMS</span> Using java program then click this <span style="color: red;"><u><a href="http://periodicupdates.blogspot.com/2011/01/using-java-send-sms.html"><span style="color: red;">Link</span></a> </u></span>and for more java program click this <span style="color: red;"><a href="http://periodicupdates.blogspot.com/search/label/Programming" style="color: red;">Link.</a></span>.<br />
Do post your comments.</div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com2tag:blogger.com,1999:blog-6736427073811109816.post-17711780766089521522011-02-02T09:16:00.000-08:002011-02-02T20:51:29.421-08:00Search String in a file<div dir="ltr" style="text-align: left;" trbidi="on">This program will help you to search the string from the file.Just go through the program you can easily understand.<br />
Here i used command line argument to search string in the file.You can replace the args[i] in the program to meet your requirement.<br />
<pre class="brush: java;">import java.io.*;
public class stringSearcher {
public static void main(String args[]) {
try {
//Give your file path here.
File file = new File("C:\\Documents and Settings\\" +
"sriram\\Desktop\\workspace.txt");
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
int linecount = 0;
String line;
while((line=bufferedReader.readLine())!= null) {
/*
* Here Searching word is passed using command line argument.
* Replace the args[i] in stringFound to the actual string you are looking for.
* you can pass the value from properties file also.
* According to your requirement you change it.
*/
int length = args.length;
for(int i=0;i<length (stringfound="" ;i++)="" if="" int="" linecount++;="" stringfound="line.indexOf(args[i]);" {=""> -1) {
System.out.println("At "+stringFound+" Searching word...."+args[i]+"...found in fileName***"+file.getName());
} else {
System.out.println("Searching word..."+args[i]+"...not found in fileName***"+file.getName());
}
}
}
bufferedReader.close();
}
catch (IOException excep) {
System.out.println("Exception occured***"+ excep.toString());
}
}
}
</pre>For more java programming click this <a href="http://periodicupdates.blogspot.com/search/label/Programming" style="color: red;">Link.</a></div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com1tag:blogger.com,1999:blog-6736427073811109816.post-44113533425771692552011-01-30T08:34:00.000-08:002011-02-15T00:32:00.706-08:00Send SMS using Java<div dir="ltr" style="text-align: left;" trbidi="on">In most of the forums i found this question.How to send SMS Using java.<br />
For answering this question i spent few hours for you guys.<br />
<br />
<br />
For sending SMS you need to have the following files<br />
1) <span class="pBody postableBody">javax.comm.properties</span><br />
<span class="pBody postableBody">2)</span><span class="pBody postableBody"> comm.jar</span><br />
<span class="pBody postableBody">3) </span><span class="pBody postableBody">win32com.dll</span><br />
In this <a href="http://www.megaupload.com/?d=XSPXW2PY" style="color: red;">Link</a> you can download the files.Let me know if the given link is broken.So that i will upload the files and change the link here.<br />
<br />
<span class="pBody postableBody">Check the java_home twice</span><span class="pBody postableBody"> before copy and paste the files.Because most of the problems occurred by pasting the files in wrong folder.</span><u style="color: red;"><span class="pBody postableBody"> </span></u><br />
<div style="color: blue;"><u><span class="pBody postableBody">javax.comm.properties</span></u><span class="pBody postableBody">: </span></div>Should falls under<br />
%JAVA_HOME%/lib<br />
%JAVA_HOME%/jre/lib<br />
<div style="color: blue;"><u>win32com.dll:</u></div>Should falls under<br />
%JAVA_HOME%/bin<br />
%JAVA_HOME%/jre/bin<br />
%windir%System32<br />
<div style="color: blue;"><u>comm.jar</u>:</div> Should falls under<br />
%JAVA_HOME%/lib<br />
%JAVA_HOME%/jre/lib/ext<br />
<br />
Okay i believe you placed all files in respective folder correctly.<br />
Wait guys i heard your mind voice,you are asking where is the java program.<br />
How i will forget,here you go for java programs<br />
<br />
<pre class="brush: java;">import java.io.IOException;
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.UnsupportedCommOperationException;
public class SriramSMS {
public void sendsms()
{
static Enumeration portList;
static CommPortIdentifier portId;
static SerialPort serialPort;
static OutputStream outputStream;
String messageString = "";
String userName="";
String phoneNumber="";
Thread thread;
try
{
userName = "periodicUpdates.blogspot.com";
phoneNumber = "9876543210";
messageString = " Hi." +userName+"welcome to this blog" ;
String line1 = "AT+CMGF=1\r\n";
String line2 = "AT+CMGS=" + phoneNumber + "\r\n"+messageString+ "\r\n";
String line3 = "\u001A";
// Here initialize the driver class
String driverName = "com.sun.comm.Win32Driver";
CommDriver commdriver = (CommDriver)Class.forName(driverName).newInstance();
commdriver.initialize();
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements())
{
portId = (CommPortIdentifier) portList.nextElement();
if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println("SMS Sending........" + portId.getName());
if((portId.getName().equals("COM1"))) {
try
{
serialPort = (SerialPort) portId.open("SimpleWriteApp",10000);
System.out.println("sms sending port--->"+serialPort);
outputStream = serialPort.getOutputStream();
serialPort.setSerialPortParams(230400,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
outputStream.write(line1.getBytes());
outputStream.write(line2.getBytes());
outputStream.write(line3.getBytes());
outputStream.flush();
thread.sleep(5000);
serialPort.close();
} catch (PortInUseException portUse) {
System.out.println("Port In Use " + portUse.toString());
} catch (UnsupportedCommOperationException unsuppComOperExcep) {
System.out.println("UnsupportedCommOperationException occured:::"+unsuppComOperExcep.toString());
} catch (IOException ioExcep) {
System.out.println("Error occured while writing to output stream IOException" + ioExcep.toString());
} catch(Exception excep) {
System.out.println("Error writing message with exception while closing " +excep.toString());
}
}
}
}
} catch(Exception excep) {
System.out.println("EXCEPTION raised while writing message@@" +excep.toString());
}
}
}</pre>You got the program for sending sms through java program.<br />
<br />
Want to <span style="color: magenta;">Send Mail</span> Using java program then click this <a href="http://periodicupdates.blogspot.com/2011/02/send-mail-in-specific-time-interval.html"><span style="color: red;">Link</span></a> and for more java program click this <a href="http://periodicupdates.blogspot.com/search/label/Programming" style="color: red;">Link</a>.<br />
Do post your comments.</div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com52tag:blogger.com,1999:blog-6736427073811109816.post-23959131660338283152011-01-29T08:32:00.000-08:002013-02-25T21:11:28.028-08:00Interview Questions<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on">Like you guys i also surfed and prepared for the interview.Few months before got selected in one MNC Company.I can help you guys by providing set of interview questions.<br />
<br />
By clicking this <a href="https://8854740435762583752-a-1802744773732722657-s-sites.googlegroups.com/site/ramsriiq/home/InterviewQuestions.rar?attachauth=ANoY7cpzcAetZdNdYzteK-Jhr3S8wC_A9sjt6Mq55qZo5EtrXqduq7FZUX70W5iI3bd0xgp8Jyuiv4tGtnJx1DmyzyBF3jbTFLJNP9Cl8bMDpijzzBFjHyGfeotlQFvIkD5AwzEaF7rm3juhcr3kfUTuJyEFhSyy9mxod0craGo9YxRpZ_2x7CSl5Cs-hhLdzN50LL0SG6EylhmZFKDYTMbzrmokjEs39A%3D%3D&attredirects=0&d=1" style="color: red;">Link</a> you can download the interview questions in rar file format.<br />
<br />
why you are waiting just download the files and rock the interview.<br />
<br />
All the best guys...</div></div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com1tag:blogger.com,1999:blog-6736427073811109816.post-18977761526416178912011-01-27T05:28:00.000-08:002011-03-16T03:31:07.911-07:00Struts2 Select Box Error.<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on">I believe you faced this error thats why you are here for the solution.<br />
Instead of wasting our time straightly we will go to the solution.<br />
<br />
<div style="color: blue;"><u>struts.xml</u></div><pre class="brush: java;"><action class="com.demo.actions.SelectList" name="selectDay">
<result name="success">/jsp/selectBox.jsp</result>
</action>
</pre><br />
<div style="color: blue;"><u>SelectList.java</u></div><pre class="brush: java;">package com.demo.actions;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class SelectList extends ActionSupport{
private ArrayList<string> dayList;
public String execute() throws Exception {
//instantiate the Arraylist here
dayList = new ArrayList<string>();
dayList.add("monday");
dayList.add("tuesday");
...
dayList.add("sunday");
return SUCCESS;
}
//Make sure you have created the getter and setter method for ArrayList
public ArrayList<string> getDayList() {
return dayList;
}
public void setDayList(ArrayList<string> dayList) {
this.dayList= dayList;
}
}
</string></string></string></string></pre><div style="color: blue;"><u>selectBox.jsp</u></div><pre class="brush: java;"><select headerkey="" headervalue="Select" label="Selected Day::" list="dayList" name="daysname"></select></pre></div>Thats it your code will work like a charm.<br />
Do post your comments and for more java programming click this <a href="http://periodicupdates.blogspot.com/search/label/Programming" style="color: red;">Link.</a></div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com2tag:blogger.com,1999:blog-6736427073811109816.post-39106236680413010752011-01-26T09:38:00.000-08:002011-02-02T09:18:25.432-08:00Maintain Image Aspect Ratio Using Java<div dir="ltr" style="text-align: left;" trbidi="on">In Internet i have searched more about maintaining the aspect ratio of the image using java program.After a long struggle found one example and i changed according to met my requirement.Here you go for the complete solution.<br />
<pre class="brush: java; toolbar: false; auto-links: false;">import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
class imageAspectRatio {
public static void main(String args[]) {
File file = new File("path");//Specify the input image source file location.
try {
FileInputStream fis = new FileInputStream(file);
InputStream bis = new BufferedInputStream(fis);
FileOutputStream fos = null;
Image image = (Image)ImageIO.read(bis);
int thumbWidth = 100;//Specify image width in px
int thumbHeight = 100;//Specify image height in px
int imageWidth = image.getWidth(null);//get image Widht
int imageHeight = image.getHeight(null);//get image Height
double thumbRatio = (double)thumbWidth/(double)thumbHeight;
double imageRatio = (double)imageWidth/(double)imageHeight;
//This calculation is used to convert the image size according to the pixels mentioned above
if(thumbRatio<imageRatio) {
thumbHeight = (int) (thumbWidth/imageRatio);
} else {
thumbWidth = (int) (thumbHeight*imageRatio);
}
BufferedImage thumbImage =
new BufferedImage(thumbWidth,thumbHeight,BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = thumbImage.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics.drawImage(image,0, 0, thumbWidth, thumbHeight,null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
int quality = 100;
quality = Math.max(0,Math.min(quality,100));
param.setQuality((float)quality/100.0f,false);
//output image type.
String format = "jpg";
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
ImageIO.write(thumbImage,format, new File("path"));//Specify the location for output image .
} catch(IOException ioExcep) {
ioExcep.printStackTrace();
}catch(Exception excep) {
excep.printStackTrace();
}
}
}
</pre><br />
Run this program you will get the expected result.<br />
Do post your comments and for more java programming click this <a href="http://periodicupdates.blogspot.com/search/label/Programming" style="color: red;">Link.</a> </div>Sriramhttp://www.blogger.com/profile/11624599135305762412noreply@blogger.com1