Posts

Showing posts from 2015

Redirecting application to specific URL after logout in Liferay.

You just need to append an URL after logout URL as below... your_logout_url?referer=url_to_redirect

How to extend Liferay 6.2 session timeout by AJAX call?

There are lot of solutions present on Liferay forum, stackoverflow and many more can be found on google but all are very difficult, not clear and also not working.... So I found a simple solution which is working and I am sharing it with you people, and hope you will find it helpful!!! You just have to add below line to each AJAX call success at client side (in JavaScipt / JQuery / AngularJS). Liferay.Session.extend();

How to check Ubuntu Linux operating system architecture is 32 bit OR 64 bit?

Image
To see if your Ubuntu Linux operating system architecture is 32-bit or 64-bit, open up a terminal and run the following command below. file /sbin/init     Here is the example of output. First line itself tell you  the architechture as 32-bit

How to Install MySQL on Ubuntu 14.04?

Image
Here is the simplest way to install latest MySQL server on Ubuntu 14.04. Step 1. Open Terminal(Command prompt) in Ubuntu. Step 2. Fire command given below, sudo apt-get install mysql-server Step 3. In between it will ask for Yes/No, here you have to press Yes otherwise Y and press enter key. Step 4. Further it will ask for "root" user password, just give a password of your choice and hit enter key. And that's it. Installation is finished. To start working on MySQL, just give following command in terminal, mysql -u root -p Then it will ask for "root" user password, so give password you entered at the time of installation and hit enter key. You are now ready to fire sql commands.

How to get context path in JQuery?

Suppose you want to get your context path in JS/JQuery on clicking an Button like, In JSP/HTML:- <input type="button" id="myButton"> In JQuery :- $('# myButton ').click(function() { console.log( myC ontextPath ); }); Then you can pass values to JS/JQuery as, <input type="button" id="myButton" myContextPath="${pageContext.request.contextPath}"> Then in JS/JQuery you can write as, $('# myButton ').click(function() {         var  myC ontextPath  = $(this).attr(' myC ontextPath '); console.log( myC ontextPath ); });

How to send mail from Liferay Portlet?

Image
import java.io.IOException; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletException; import com.liferay.mail.service.MailServiceUtil; import com.liferay.portal.kernel.mail.MailMessage; import com.liferay.util.bridges.mvc.MVCPortlet; /** * Portlet implementation class FeedbackPortlet */ public class FeedbackPortlet extends MVCPortlet { public void sendEmail(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { MailMessage mailMessage = new MailMessage(); mailMessage.setHTMLFormat(true); mailMessage.setBody("Your mail body"); mailMessage.setFrom(new InternetAddress("from_mail_id@something.com","Display Name in Inbox")); mailMessage.setSubject("Messag

How to clear cache programmatically in JSP?

By adding below lines in JSP page we can achive this: <%              response.setHeader("Cache-Control","no-cache"); //HTTP 1.1              response.setHeader("Pragma","no-cache"); //HTTP 1.0              response.setDateHeader ("Expires", 0); //prevents caching at the proxy server   %> Other solution is by adding below lines in <head></head> of your JSP page: <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache"> <meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">

How to remove do-search.com from Mozilla Firefox?

Step 1. Open Firefox Step 2. In Address Bar type  about:config then hit enter. Step 3. Then Click I'll be careful, I promise!  button. Step 4. Then at top in Search text box type  do-search and you will get all entries for this infection. Step 5. Right click on them one by one and select RESET option. Step 6. Then Restart Firefox.

Steps to crearte facebook application at Facebook Developers Page.

Image
For login with facebook to work we have to create a facebook application at Facebook Developers Page using following steps, 1. Login to Facebook Developers Page . 2. Goto " My Apps " menu. 3. Click " Add a New App " option. 4. In popup select " WWW " symbol which represent website login. 5. Then give a application name in provided text field. 6. Click " Create New Facebook App ID " button 7. In next screen choose " Category " of your application. 8. Then click " Create App ID " button. 9. Then on next screen give your site URL. For development purpose use http://localhost:<port number>

Create a pdf file using java and encrypt / decrypt it.

For this example to work you will need following jar files. 1.  bcpkix-jdk15on-1.47.jar 2.   itextpdf-5.1.0.jar 3.   bcprov-jdk14-146.jar Download them and include them in your project classpath . /* * This class is part of the book "iText in Action - 2nd Edition" * written by Bruno Lowagie (ISBN: 9781935182610) * For more info, go to: http://itextpdf.com/examples/ * This example only works with the AGPL version of iText. */ import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; public class EncryptionPdf { /** User password. */ public static byte[] USER = "Hello".getBytes(); /** Owner password. */ public static byte[] OWNER = "World".getBytes

How to refresh JSP page automatically after each time period?

<%@ page import="java.io.*,java.text.*,java.util.*"%> <html> <head> <title>Auto Refresh Header Example</title> </head> <body> <h2>Auto Refresh Header Example</h2> <% // Page will be auto refresh after 1 second response.setIntHeader("Refresh", 1); // Get Current Time DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); out.println(dateFormat.format(cal.getTime())); %> </body> </html>

Login with Facebook example.

Below is the code for logging our application using Facebook. Note: Please change appId : ' 45366235237356756 ' with your Facebook application ID. <div id="fb-root"></div> <script> //Load the Facebook JS SDK (function(d) { var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) { return; } js = d.createElement('script'); js.id = id; js.async = true; js.src = "http://connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); }(document)); // Init the SDK upon load window.fbAsyncInit = function() { FB.init({ appId : ' 45366235237356756 ', // App ID status : true, // check login status cookie : true, // enable cookie

How to convert 24 hr format time in to 12 hr Format?

Here is the code to convert 24-Hour time to 12-Hour with AM and PM. If you don't want AM/PM then just replace hh:mm a with hh:mm. import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String [] args) throws Exception { try { String _24HourTime = "22:15"; SimpleDateFormat _24HourSDF = new SimpleDateFormat("HH:mm"); SimpleDateFormat _12HourSDF = new SimpleDateFormat("hh:mm a"); Date _24HourDt = _24HourSDF.parse(_24HourTime); System.out.println(_24HourDt); System.out.println(_12HourSDF.format(_24HourDt)); } catch (Exception e) { e.printStackTrace(); } } } Output: Thu Jan 01 22:15:00 IST 1970 10:15 PM Another Solution: System.out.println(hr%12 + ":" + min + " " + ((hr>=12) ? "PM" : "AM"));

How to remove PayPal Developer MyApps?

Delete App facility is now added in PayPal. Goto developer.paypal.com Click  My Apps You will get all applications list Then look at right side of each application there you will get the " Delete " button. Clicking it will pops an window Write your application name in text box and click delete. That's it.

How to print any number into specific number of digits?

To print any integer in specific number of digits then we can use format() function from java.lang.String class. For e.g. public class LeadingZerosExample { public static void main(String[] args) { int number = 15; String formatted = String.format("%04d", number); System.out.println("Number with leading zeros: " + formatted); } } Output for this program will be as follows: Number with leading zeros: 0015

How to calculate time difference between a given time and current time in Java?

SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); Date date = dateFormat.parse("17:40:00"); System.out.println(date); Date date2 = new Date(); date2 = dateFormat.parse(dateFormat.format(date2)); System.out.println(date2); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Calendar calendar2 = calendar.getInstance(); calendar2.setTime(date2); System.out.println((calendar2.getTimeInMillis() - calendar.getTimeInMillis())/60000);

How to check JVM settings?

You can use below command to check all detailed settings of JVM on linux as well as windows: # java -XshowSettings:all If everything goes well then OUTPUT can be like: VM settings:     Max. Heap Size (Estimated): 1.76G     Ergonomics Machine Class: client     Using VM: Java HotSpot(TM) 64-Bit Server VM Property settings:     awt.toolkit = sun.awt.windows.WToolkit     file.encoding = Cp1252     file.encoding.pkg = sun.io     file.separator = \     java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment     java.awt.printerjob = sun.awt.windows.WPrinterJob     java.class.path = .     java.class.version = 52.0     java.endorsed.dirs = C:\Program Files\Java\jre1.8.0_31\lib\endorsed     java.ext.dirs = C:\Program Files\Java\jre1.8.0_31\lib\ext         C:\Windows\Sun\Java\lib\ext     java.home = C:\Program Files\Java\jre1.8.0_31     java.io.tmpdir = C:\Users\Neosoft\AppData\Local\Temp\     java.library.path = C:\ProgramData\Oracle\Java\javapath         C:\Window