25 Sept 2015

Demonstrating Servlet Deployment

Apparatus: 

  • XAMPP Server/Apache Tomcat (Servlet Container)
  • MS Access
  • Web Browser
  • Editor (Notepad ++)
  • Java Development Kit

Things Covered in this post:

  • Writing a java servlet program
  • Creating user DSN and using it to connect Java web application to Database (.mdb)
  • Deploying the servlet in Servlet Container
  • Running the Application in Web Browser

Summary:

Step 1: Writing a basic HTML to construct User Interface (home.html)
Step 2: Creating a Database in MS Access (Database2.mdb)
Step 3: Creating a DSN
Step 4: Writing a Java Servlet Program
Step 5: Compiling the Java Servlet Program
Step 6: Making the entry of the Java Servlet class in the descriptor file (web.xml)
Step 7: Deploying the files in appropriate directories
Step 8: Starting the Apache Tomcat module
Step 9: Checking the services running
Step 10: Running the Web Application on the Web Browser

Steps in Detail:


Step 1: Writing a basic HTML to construct User Interface (home.html): 

Step 2: Creating a Database in MS Access (Database2.mdb):

The schema of table ‘result’ in Database2.mdb:

Field Name
Data Type
Field Size
RollNo (Primary Key)
Number
Long Integer
SName
Text
255
Branch
Text
255
CPI
Number
Double

Step 3: Creating a DSN:

Open System & Security/ Administrative Tools from Control Panel. Select ODBC Data Sources (32-bit). Click on User DSN tab and click Add…Button.


Select Driver do Microsoft Access (*.mdb).

 
Give the Data Source Name and click the Select…  button to link the database file. Then click the OK button.

Step 4: Writing a Java Servlet Program:

Step 5: Compiling the Java Servlet Program:

First time compilation of Java Servlet Program would fail because libraries (servlet-api.jar at location C:\xampp\tomcat\lib ) consisting of servlet classes are not present in installed jdk. So you need to set the User variable CLASSPATH in Environment Variables which you will find in Advanced system settings in Control Panel as shown:



User variables:

Variable
Value
CLASSPATH
.;C:\xampp\tomcat\lib\servlet-api.jar



System variables:

Variable
Value
JAVA_HOME
C:\Program Files (x86)\Java\jdk1.6.0_24
Path
C:\Program Files (x86)\Java\jdk1.6.0_24\bin


Restart the computer after setting the variables.




Note: Locations may differ as per the different installation directories.

Step 6: Making the entry of the java servlet class in the descriptor file (web.xml):
 
web.xml is a descriptor file which consists the information of all the servlet classes present in the web application. The URLs to access the servlets are specified in this file.

Step 7: Deploying the files in appropriate directories:

This zip file consists of following files at following locations:

1.       home.html (C:\xampp\tomcat\webapps\student)
2.       Database2.mdb (C:\xampp\tomcat\webapps\student)
3.       web.xml (C:\xampp\tomcat\webapps\student\WEB-INF)
4.       Result.java (C:\xampp\tomcat\webapps\student\WEB-INF\classes)
5.       Result.class (C:\xampp\tomcat\webapps\student\WEB-INF\classes)

You can even directly extract student.rar file to C:\xampp\tomcat\webapps.

Step 8: Starting the Apache Tomcat module:

Start the Apache Tomcat from XAMPP Control Panel.

 
Step 9: Checking the services running:

In order to check whether the Apache Tomcat has started or not, simply type the following URL in your web browser:
localhost:8080

Step 10: Running the Web Application on the Web Browser:

To run this web application, type the following URL:


http://localhost:8080/student/home.html



Note: Every time you make changes to your servlet program, after compilation you need to restart the Apache Tomcat in order to reflect the changes.
 


 

 

 

  


 

·        
 

 



·         

 



24 Jun 2015

Notes on Database Management System (DBMS) and Business Information System (BIS)

Follow the link to download the notes:


                Content of DBMS notes comprises of basic concepts of DBMS, Join, Normalization, etc. and also comprises of lab work which includes basic queries and procedures and much more.

                
                BIS notes comprises content related to Business Process, Business Levels and its Forms, Data System, Introduction to Artificial Intelligence, System Investigation, System Design and Implementation, Payroll and Inventory Management Systems.

16 May 2015

Amazing Random Class Variables



Playing Android Games is an amazing experience as every time one plays the game, s/he comes across new obstacles, new villains of different sizes, different colors, different numbers, new backgrounds and much more. This feature retains the interest of the player in the game by preventing the boredom which is created when the player plays the games which loads the same components every time.

This amazing feature is achieved with the help of Random class variables. These variables generate random values restricted to the limit specified every time they are executed.

Let us learn the use of Random class variables with simple example. Let us create an Android application which will generate random colors in the 3 x 3 grid every time the “Play” button is pressed.

Code:

package com.example.randomcolorsgenerator;

import java.util.Random;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.widget.*;

public class MainActivity extends Activity {

TextView t[] = new TextView [9];
Button b1;
int i,red,green,blue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t[0] = (TextView)findViewById(R.id.tv1);
        t[1] = (TextView)findViewById(R.id.tv2);
        t[2] = (TextView)findViewById(R.id.tv3);
        t[3] = (TextView)findViewById(R.id.tv4);
        t[4] = (TextView)findViewById(R.id.tv5);
        t[5] = (TextView)findViewById(R.id.tv6);
        t[6] = (TextView)findViewById(R.id.tv7);
        t[7] = (TextView)findViewById(R.id.tv8);
        t[8] = (TextView)findViewById(R.id.tv9);
        b1 = (Button)findViewById(R.id.button);
   
            b1.setOnClickListener(new View.OnClickListener() {
               
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    try{
                    Random r = new Random();
                    for(i=0;i<9;i++){
                        red = r.nextInt(256);
                        green = r.nextInt(256);
                        blue = r.nextInt(256);
                        t[i].setBackgroundColor(Color.rgb(red,green,blue));
                        t[i].setText(red+","+green+","+blue);
                    }
                    }
                   
                    catch(Exception e){}
                }
           
            });
  
    }
   
}

Layout file:


Snapshots:


15 May 2015

Are you a Java Programmer – If yes, aren’t you an Android Developer?



Developing Android Applications is easier if you are a java programmer. Android Developer Tools comes with a pack of numerous classes which enables you to develop Android Applications. Before starting you should have the basic idea about how you would set up your android development environment. You will require:

  • Java JDK
  • Eclipse IDE
  • Android ADT
  • Android SDK

 I recommend Android Application Development Tutorials playlist (200 videos) by thenewboston on YouTube to learn developing android applications:
               

Here you will learn about:

  • Setting up your android development environment in detail
  • Layouts
  • Use of various inbuilt classes and its methods
And much more..!  

12 May 2015

Solution to the problem faced while syncing data with excel using java applet

In previous posts, we saw java programs in which we used applet to sync the entered data in the excel sheet. But when you run the program, you would face problem while writing the data to the file and opening of the file using applet's button. So add:

grant{
permission java.security.AllPermission;
}


statement in java.policy (C:\Program Files\Java\jdk1.8.0_05\jre\lib\security)
file.