Search This Blog

Monday, 17 November 2014

How to check whether Submit Button is disabled in JQuery ?


 How to check whether Submit Button is disabled in JQuery ?
        if($('#submitButton').is(':disabled')){
        //Code to be executed
       }

How to Enable button in Jquery  ?
         $('#submitButton').attr("disabled", false);

How to Disable button in Jquery  ?
        $('#submitButton').attr("disabled", true);

How to change value of Submit button in Jquery  ?
        $('#submitButton').val('Please wait ... Processing');


 Code :

$('#submitButton').click(function() {
                    if($('#submitButton').is(':disabled'))
                     {

                        $('#submitButton').attr("disabled", false);
                        $('#submitButton').val('Submit');

                     }
                    else
                    {
                       $('#submitButton').attr("disabled", true);
                        $('#submitButton').val('Please wait ... Processing');

                     }

Friday, 1 August 2014

How to unlock Android phone if Forgot Pattern

Many times our pattern lock's pattern is too much complicated to remember, In this case there are chances of Forgetting Pattern is more. So, What to do if you forgot pattern ? How to unlock Android phone with forgotten patten lock ? or How to bypass android pattern lock screen ? If these questions are in your mind then here We've provided the perfect solutions to Unlock android phone after forgotten patten lock.

unlock-bypass-android-pattern-if-forgot
There are many methods for unlocking (bypassing) android pattern lock after forgotten pattern that I have found on the Internet forum. I am explaining those methods to bypass android pattern lock with more clear views.

Note : If none of these method works sadly you have to wipe whole data of your phone.


Disclaimer :
This guide if for Education purpose only and only for those people who have forgotten their pattern lock screen. You shall not use these methods to someone's phone without the permission of the owner. We are not responsible for any kind error occurs during this processes. Files and tutorials are created according to our experience and collected from Internet and XDA forums.

So, let's start the methods to bypass/unlock Android pattern lock.

Method #1 : Flash ZIP and via CWM and ByPass Pattern lock screen :

  • Download the Pattern lock disable zip file from this link.
  • Move that zip file to the SDcard of your phone using a card reader.
  • Now insert that SDcard to you phone.
  • Reboot your phone into recovery mode (For this first switch of your phone and then keep pressing Volume Up+Home+Power button till recovery screen appear.)
  • Now flash the zip file which you've downloaded using recovery mode and then reboot your android smartphone.
  • Guess what ? You're done pattern lock of your Android smartphone shall be disable.

Method #2 : ByPass Android pattern lock screen using ADB :

  • For this method you need A computer running with a Linux distro or Windows+Cygwin and USB cable to connect your phone with PC.
  • Open Terminal from you PC and type below code in it.
sudo apt-get install android-tools-adb
  • Then hit Enter.
  • Now connect your Android phone with PC using USB Cable.
  • Then open a terminal window in PC and type below code in it.
adb devices
adb shell
cd data/system
su
rm *.key
  •  You're done ! Now just restart your android phone.
Note : If it ask for pattern lock after restarting, Don't worry...Just enter a random pattern and you're phone should be unlock.

Method #3 : ByPass Android pattern lock via SMS :

  • For this method You've to installed a application to your phone before the lock accident occurs.
  • Download SMS ByPass application from this link. (This app require root access to run.)
  • First make sure, You've given permanent root access to the app.
  • Change the secret code in the app, the by default code is :1234
  • Now, when you forgot your pattern lock or  Password of your android just send SMS from other as shown below.
1234 reset
Note : Where 1234 is your secret code, which you've select in the app. If you've changed it you need to send the new secret code via SMS as above format.

So, these are the 3 easy methods to bypass or unlock Android pattern lock if Forgot pattern. If these all method won't work for you then you've to reset your phone using CWM by 'wipe data and cache' option. This will delete all the data of your phone including Application and contacts of your Android phone.

If you liked above method then take a second to share this with your friends, It may be help them, Sharing is caring

Wednesday, 30 July 2014

Show/Hide HTML Tags using JavaScript

Show/Hide HTML div tags using JavaScript



<script type="text/javascript">
function showHide(divId)
{
    var theDiv = document.getElementById(divId);
    if(theDiv.style.display=="none")
  {
        theDiv.style.display="";
   }
   else
   {
        theDiv.style.display="none";
       }   
}
</script>

<input type="button" onclick="showHide('div1')" value="Test It">
<div id="div1" style="">
<h1>This is Demo</h1>
</div>

jQuery: Get Value Of Input, Textarea and Radio Button,Select,Option






HTML Forms contains various elements like input fields, options, textarea ,option etc. No doubt for further processing,  there is a need to get value of each field.

we have taken four form elements in our example – input field, radio button and a textarea,option.
  • To get value of input field.
$("input").val();
  • To get value of Checked Radio Button.
$("form input[type='radio']:checked").val();
  • Get value of Radio button with onChange.
$('input:radio').change(function(){
 var value = $("form input[type='radio']:checked").val();
 alert("Value of Changed Radio is : " +value);
 });
  • To get value of Textarea field.
$("textarea").val();
  • To Read Select Option Value
$('#selectId').val();
  • To Set Select Option Value
$('#selectId').val('newValue');
  • To Read Selected Text
$('#selectId>option:selected').text();




Friday, 18 July 2014

AJAX with Servlets/JSP using JQuery and JSON



 To do this, let us get introduced to JSON(Javascript Object Notation), in addition to JQuery and AJAX. JSON is derived from Javascript for representing simple data structures and associative arrays, called objects. Here in our scenario, we are going to use a JSON library in Servlet to convert Java objects (lists,maps,arrays.etc) to JSON strings that will be parsed by JQuery in the JSP page and will be displayed on the web page.


There are many JSON libraries available that can be used to pass AJAX updates between the server and the client. I am going to use google's gson library in this example. 

Now, let us create a simple JSP page with two drop down lists, one that contains values for countries and the other that is going to be populated with values for states based on the value of country selected in the first drop down list. Whenever the value is selected in the "country" drop down list, the "states" drop down list will be populated with corresponding state values based on the country selected. This has to be done without a page refresh, by making AJAX calls to the servlet on the drop down list change event.

Here are the steps to reproduce in Eclipse,

1. First of all create a "Dynamic Web Project" in Eclipse.
2. Create a new JSP page under "Webcontent" folder and copy paste the below code in it.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>AJAX calls to Servlet using JQuery and JSON</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
    $(document).ready(function() {
        $('#country').change(function(event) {  
        var $country=$("select#country").val();
           $.get('ActionServlet',{countryname:$country},function(responseJson) {   
            var $select = $('#states');                           
               $select.find('option').remove();                          
               $.each(responseJson, function(key, value) {               
                   $('<option>').val(key).text(value).appendTo($select);      
                    });
            });
        });
    });          
</script>
</head>
<body>
<h1>AJAX calls to Servlet using JQuery and JSON</h1>
Select Country:
<select id="country">
<option>Select Country</option>
<option value="India">India</option>
<option value="US">US</option>
</select>
<br/>
<br/>
Select State:
<select id="states">
<option>Select State</option>
</select>
</body>
</html>


3. Download google's GSON library from here and place it in your project's WEB-INF/lib folder.
4. Create a servlet in the name 'ActionServlet' (since I have used this name in the jquery code above') in the src directory. Copy and paste the below code in the doGet() method of the servlet and add the import statement in the header section of the servlet.


import com.google.gson.Gson;

protected void doGet(HttpServletRequest request,   HttpServletResponse response) throws ServletException, IOException {
String country=request.getParameter("countryname");
Map<String, String> ind = new LinkedHashMap<String, String>();
    ind.put("1", "New delhi");
    ind.put("2", "Tamil Nadu");
    ind.put("3", "Kerala");
    ind.put("4", "Andhra Pradesh");
    
    Map<String, String> us = new LinkedHashMap<String, String>();
    us.put("1", "Washington");
    us.put("2", "California");
    us.put("3", "Florida");
    us.put("4", "New York");
    String json = null ;
    if(country.equals("India")){
     json= new Gson().toJson(ind);   
    }
    else if(country.equals("US")){
     json=new Gson().toJson(us);  
    }
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(json);     
}

}


In the above code, we create two maps for two countries, and return the one based on the country parameter passed to the servlet in the AJAX call made by the JQuery's get() method. Here we convert the map objects to json strings in order to send the response back to the JSP page.

5. Make sure you have done servlet mapping properly in web.xml file. An example of this is given below,

<servlet>
    <servlet-name>ActionServlet</servlet-name>
    <servlet-class>ajaxdemo.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ActionServlet</servlet-name>
    <url-pattern>/ActionServlet/*</url-pattern>
</servlet-mapping>

In the above code,'ajaxdemo' is the package name in which I have created the servlet. Replace it with your package structure to make the servlet work properly.



Thats it! You are now all set to run the project with Tomcat. When you run this project, the second drop down list will be populated automatically when you change the value in the first drop down list. 

Output Screenshots:

First drop down list changing,


On selecting 'India' in the first drop down list,


On selecting 'US' in the first drop down list,




Please leave your comments and queries about this post in the comment sections in order for me to improve my writing skills and to showcase more useful posts. 

Tuesday, 15 July 2014

File Upload Example in Struts

 

 

Required JAR file

Before we start, we need to make sure commons-io.jar file is present in the classpath. Following are the list of required Jar files.
struts2-file-upload-jar-files

Getting Started

In order to add file upload functionality we will add an action class FileUploadAction to our project. Create file FileUploadAction.java in package com.blogspot.rajvishwakarma15.struts2.
FileUploadAction.java
package com.blogspot.rajvishwakarma15.struts2;
 
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
 
public class FileUploadAction extends ActionSupport implements
        ServletRequestAware {
    private File userImage;
    private String userImageContentType;
    private String userImageFileName;
 
    private HttpServletRequest servletRequest;
 
    public String execute() {
        try {
            String filePath = servletRequest.getSession().getServletContext().getRealPath(“/”);
            System.out.println("Server path:" + filePath);
            File fileToCreate = new File(filePath, this.userImageFileName);
 
            FileUtils.copyFile(this.userImage, fileToCreate);
        } catch (Exception e) {
            e.printStackTrace();
            addActionError(e.getMessage());
 
            return INPUT;
        }
        return SUCCESS;
    }
 
    public File getUserImage() {
        return userImage;
    }
 
    public void setUserImage(File userImage) {
        this.userImage = userImage;
    }
 
    public String getUserImageContentType() {
        return userImageContentType;
    }
 
    public void setUserImageContentType(String userImageContentType) {
        this.userImageContentType = userImageContentType;
    }
 
    public String getUserImageFileName() {
        return userImageFileName;
    }
 
    public void setUserImageFileName(String userImageFileName) {
        this.userImageFileName = userImageFileName;
    }
 
    @Override
    public void setServletRequest(HttpServletRequest servletRequest) {
        this.servletRequest = servletRequest;
 
    }
}
In above class file we have declared few attributes:
  • private File userImage; -> This will store actual uploaded File
  • private String userImageContentType; -> This string will contain the Content Type of uploaded file.
  • private String userImageFileName; -> This string will contain the file name of uploaded file.
The fields userImageContentType and userImageFileName are optional. If setter method of these fields are provided, struts2 will set the data. This is just to get some extra information of uploaded file. Also follow the naming standard if you providing the content type and file name string. The name should be ContentType and FileName. For example if the file attribute in action file is private File uploadedFile, the content type will be uploadedFileContentType and file name uploadedFileFileName.
Also note in above action class, we have implemented interface org.apache.struts2.interceptor.ServletRequestAware. This is to get servletRequest object. We are using this path to save the uploaded file in execute() method. We have used FileUtil.copyFile() method of commons-io package to copy the uploaded file in root folder. This file will be retrieved in JSP page and displayed to user.

The JSPs

Create two JSP file in WebContent folder. UserImage.jsp will display a form to user to upload image. On submit, the file will be uploaded and saved on server. User will be sent to SuccessUserImage.jsp file where File details will be displayed. Copy following code into it.
UserImage.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Upload User Image</title>
</head>
 
<body>
<h2>Struts2 File Upload & Save Example</h2>
<s:actionerror />
<s:form action="userImage" method="post" enctype="multipart/form-data">
    <s:file name="userImage" label="User Image" />
    <s:submit value="Upload" align="center" />
</s:form>
</body>
</html>
SuccessUserImage.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Success: Upload User Image</title>
</head>
<body>
    <h2>Struts2 File Upload Example</h2>
    User Image: <s:property value="userImage"/>
    <br/>
    Content Type: <s:property value="userImageContentType"/>
    <br/>
    File Name: <s:property value="userImageFileName"/>
    <br/>
    Uploaded Image:
    <br/>
    <img src="<s:property value="userImageFileName"/>"/>
</body>
</html>

Struts.xml entry

Add following entry for FileUploadAction class to struts.xml file.
<action name="userImage"
    class="com.blogspot.rajvishwakarma15.struts2.FileUploadAction">
    <interceptor-ref name="fileUpload">
        <param name="maximumSize">2097152</param>
        <param name="allowedTypes">
            image/png,image/gif,image/jpeg,image/pjpeg
        </param>
    </interceptor-ref>
    <interceptor-ref name="defaultStack"></interceptor-ref>
    <result name="success">SuccessUserImage.jsp</result>
    <result name="input">UserImage.jsp</result>
</action>
Note that in above entry we have specified two parameter to fileUpload interceptor, maximumSize and allowedTypes. These are optional parameters that we can specify to interceptor. The maximumSize param will set the maximum file size that can be uploaded. By default this is 2MB. And the allowedTypes param specify the allowed content types of file which can be uploaded. Here we have specified it to be an image file (image/png,image/gif,image/jpeg,image/pjpeg).
The file upload interceptor also does the validation and adds errors, these error messages are stored in the struts-messsages.properties file. The values of the messages can be overridden by providing the text for the following keys:
  • struts.messages.error.uploading – error when uploading of file fails
  • struts.messages.error.file.too.large – error occurs when file size is large
  • struts.messages.error.content.type.not.allowed – when the content type is not allowed

That’s All Folks

Compile and Execute the project in eclipse and goto link http://localhost:8080/StrutsHelloWorld/UserImage.jsp
Image Upload Screen
struts2-file-upload-example
Image Upload Screen in case of error
struts2-file-upload-error
Image Upload Screen on success
struts2-file-upload-success

Download Source Code

Click here to download Source Code without JAR files (20KB)


Monday, 7 July 2014

How to Hack Windows 7 Administrator or User Password?

How to Hack Windows 7 Administrator or User Password?

We have already written several windows 7 password recovery tips on this blog. Today
we will tell you how to hack Windows 7 password if locked out of computer? Yes, there
 kinds of Windows 7 password hacker ways with which you can get pass windows 7 login
 screen even when you forgot windows 7 login password.
hack windows 7 password

Hack Windows 7 Password without Software


There are 2 types of account on Win 7 by default. There is local account or Windows live
 or hotmail account. The former stores the login on PC, while the latter connects to the 
online hotmail or live email id. Here I would like to show you Windows 7 password reset 
with default Windows 7 administrator account.

Tip 1: Hack Windows 7 Login Password with Default Windows 7 Administrator Account


First you need to boot Win 7 in safe mode as it is disabled in normal mode. When you are in
 safe mode, this default Windows admin account enabled to login Win 7 with a blank password.
 The you can remove the forgotten user account under users in control panel. Below is step by
 step guide for you:

1. Press on the F8 key while you start Windows 7 until your PC displays the boot menu.
2. Select Safe Mode option and press the Enter key
3. Then a login box appears, click on Administrator in the username box and leave the
password field as blank, click on OK to login.
4. Now you can open Control Panel, then in User Accounts you can reset any user password
easily.

Tip 2: Hack Password Windows 7 with Password Reset disk


It seems quite simple to hack Windows 7 password if you have Win 7 password reset disk.
 Assure that you have created it in advance. Otherwise, you change to hack Windows
 7 password is over. Now you lost Windows 7 password, it is time for you to find it and
 use it. It is easy to reset Windows 7 password with it, what you need to do is follow
 the step by step wizard to create a new login password to the current user.

If the above Windows 7 password hacker methods don’t work at all for you, don’t worry. These
 windows 7 password hacker methods in the above list are helpful, but might be unsuitable for
 your case. In this condition, you can have a try Windows password reset tool designed for Win 7.

Hack Forgotten Windows 7 Password with Software


One of the popular Windows 7 password hacker tool which is confirmed to replace your forgotten
 windows 7 password with blank so that you can login without entering any password, it is Windows
 Password Key.

Windows Password Key resets any Windows password, such as
Windows 8/7/Vista/XP/2012/2011/2008/2003/2000. It can hack domain passwords as well.
No matter how complicated your Windows 7 password, Windows Password
 Key can reset it within 4 minutes. It’s easy to use, whether for beginners or advanced users.
 And it comes with ready-only and non-destructive designs to make sure it has no data loss 
on your computer. 



You can go to its official website to for more information: www.lostwindowspassword.com



After reading this article, you should have learned how to hack Windows 7 password when
 you forgot or lost the password. If not, read it again. By the way, you can also hack
 Windows 8/Vista/XP/2012/2011/2008/2003/2000 password as these methods.

Sunday, 29 June 2014

The type 'Microsoft.SqlServer.Management.Sdk.Sfc.ISfcHasConnection' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'.

 I think the error is fairly explanatory, include a reference to Microsoft.SqlServer.Management.Sdk.Sfc. You have not listed that you added that reference. Sometimes when you add references that use other dll reference's that were not included, then you have to include those other references...even if you are not using them.

Friday, 27 June 2014

Why multiple inheritance is not supported in Java !!!

Why Java doesn't support multiple inheritance

1) First reason is ambiguity around Diamond problem, consider a class A has foo() method and then B and C derived from A and has there own foo() implementation and now class D derive from B and C using multiple inheritance and if we refer just foo() compiler will not be able to decide which foo() it should invoke. This is also called Diamond problem because structure on this inheritance scenario is similar to 4 edge diamond, see below

           A play()
           / \
          /   \
play() B     C play()
          \   /
           \ /
            D
           play()

In my opinion even if we remove the top head of diamond class A and allow multiple inheritances we will see this problem of ambiguity.

Some times if you give this reason to interviewer he asks if C++ can support multiple inheritance than why not Java. hmmmmm in that case I would try to explain him the second reason which I have given below that its not because of technical difficulty but more to maintainable and clearer design was driving factor though this can only be confirmed by any of java designer and we can just speculate. Wikipedia link has some good explanation on how different language address problem arises due to diamond problem while using multiple inheritances.

2) Second and more convincing reason to me is that multiple inheritances does complicate the design and creates problem during casting, constructor chaining etc and given that there are not many scenario on which you need multiple inheritance its wise decision to omit it for the sake of simplicity. Also java avoids this ambiguity by supporting single inheritance with interfaces. Since interface only have method declaration and doesn't provide any implementation there will only be just one implementation of specific method hence there would not be any ambiguity.