Engineering College, Bikaner: Advance Java (J2EE)
Engineering College, Bikaner: Advance Java (J2EE)
Engineering College, Bikaner: Advance Java (J2EE)
Submitted To:-
Mr. Rituraj Soni Assistant Professor Department of Computer Science & Engineering
ACKNOWLEDGEMENT
I have taken efforts in this project. However, it would not have been possible without the kind support and help of many individuals and organizations. I would like to extend my sincere thanks to all of them. I would like to express my deepest appreciation to Government Engineering College, Bikaner for every support and opportunities provided time to time. I am highly indebted to Acme Embedded Technologies Pvt. Ltd., Bikaner for their guidance and constant supervision as well as for providing necessary information regarding the project & also for their support in completing the project.
I would like to express my gratitude towards my parents & Mr. Manish Shandilya (Director of Acmeet Group) for their kind co-operation and encouragement which help me in completion of this project.
My thanks and appreciations also go to my colleague in developing the project and people who have willingly helped me out with their abilities.
Submitted By: Priya Verma Submitted to: Mr. Rituraj Soni Incharge Practical Training & Seminar CSE I
PREFACE
To develop a project in any language means to combine all the features of the language, in a well planned, systematic way so as to develop and application after an analysis of requirement, so that it will be commercially helpful. In terms of its ultimate objectives it gives an experience of realistic application. The aim of this project is too realistic, efficient, by using programming in Java. The project was aimed to achieve full fledge user friendliness. We have tried a lot to achieve all the characteristics of good website.
ORGANIZATION PROFILE
Acme Embedded Technologies Pvt. Ltd. - A Website & Software development company in INDIA which offers website design, web solutions business and also quality web design. Our main focus is to satisfy their clients with high quality services. We are expert in all types of projects from large IT projects to web based projects to internet pluses. Our clientele gain great web services and web solution within the time and at reasonable rates. Our high quality services help our customers to achieve their tactical targets very soon.
Services of the company Custom Web Programming (J2EE, PHP, ASP.NET) Website Design (Web, Graphics, Logo) Web Hosting Software Development Training (C , C++ , Java , Advance Java , PHP/MySQL , C#.net , Asp.net , Salesforce , Oracle , OCJP etc.)
CONTENTS
Sno Chapter About JAVA Characteristics of JAVA JAVA Swing JDBC Introduction to JDBC JDBC Architecture Database connectivity JDBC Drivers JDBC Connections Close Connections JSP(JAVA Server Pages) Introduction to JSP JSP Server Servlets Vs. JSP Developing First page Declarations Attribute JAVA Scriptles Cookie Session Objective of Project Meaning of Project Introduction to Project System Specification Page No
1. 2. 3.
4.
5.
Chapter 1
About JAVA
The entire component has been developed using Java technology. Java has been chosen as the platform because of its feature rich nature. The Java Platform provides robust end-to-end solutions for networked applications as well as a trusted standard for embedded applications. So Java was a natural choice for development process.
Characteristics of Java
Object Oriented: Java is object oriented to the truest sense of the word. Everything in Java is represented as objects. Variables and methods both are encapsulated in objects. Java is the purest object-oriented language. Robust: Java is a very robust language owing to the following features. Excellent exception handling facilities. Memory management relief for the user. User does not have to worry about allocation and deallocation of memory. Strict compile-time and runtime checks for data types.
Portable and Architecture-neutral (Platform Independent): Java is portable and platform independent so much that they satisfy write once; run anywhere, anytime, forever. This feature is implemented in the following ways: Compiler generates machine independent byte-code instructions which can be run on any machine supporting Java Virtual Machine. Size of primitive data type is machine independent. Programs can do many things simultaneously using different threads. Provides a solution for multiprocess synchronization. Allows the creation of networked and interactive programs. Open access to remote objects by the use of RMI (Remote Method Invocation). Brings a level of abstraction to client/server programming.
Multithreaded:
Distributed:
Secure: Security is achieved by confining a java program to the java execution environment and not allowing access to other parts of the user computer. Absence of pointers provides memory related security as encroachment of memory avoided Proper measures for prevention of viral infection and malicious intent. is
Facilitates linking in of new classes, objects and methods. Supports native methods (methods written in other languages like C, C++). Programs carry with them a substantial amount of runtime type information that is used to verify and resolve accesses to objects at run-time.
High Performance: Just-In-Time (JIT) compilers are used to convert byte-code into native machine code resulting in very high performance. These JIT compilers can be used on a real time, piece by piece demand basis to perform on-the-fly compilation of byte-code into native-code.
Chapter-2 JAVA Swing Swing IntroductionSwing library is an official Java GUI toolkit released by Sun Microsystems. It is used to create Graphical user interfaces with Java.
Swing Components:
Basic Controls: JButton JCheckBox JComboBox JList JMenu JRadioButton JSlider JSpinner JTextField JPasswordField Interactive Displays of Highly Formatted Information: JColorChooser JEditorPane JFileChooser JTable JTextArea JTree Uneditable Information Displays: JLabel JProgressBar JSeparator JToolTip Top-Level Containers: JApplet JDialog JFrame
General-Purpose Containers: JPanel JScrollPane JSplitPane JTabbedPane JToolBar Special-Purpose Containers: JInternalFrame JLayeredPane Root pane
Chapter-3 JAVA DATABASE CONNECTIVITY (JDBC) Introduction JDBC stands for Java Database Connectivity. The Java JDBC API enables Java applications to connect to relational databases via a standard API, so your Java applications become independent (almost) of the database the application uses. Using JDBC you can send SQL, PL/SQL statements to almost any relational database. JDBC is a Java API for executing SQL statements and supports basic SQL functionality.
The JDBC library includes APIs for each of the tasks commonly associated with database usage: Making a connection to a database Creating SQL statements Executing that SQL queries in the database Viewing & Modifying the resulting records
JDBC ArchitectureThe JDBC API supports both two-tier and three-tier processing models for database access.
Main components of JDBCDriverManager: Manages a list of database drivers. Matches connection requests from the java
application with the proper database driver using communication subprotocol. The first driver that recognizes a certain subprotocol under JDBC will be used to establish a database Connection.
Driver: The database communications link, handling all communication with the database.
Normally, once the driver is loaded, the developer need not call it explicitly.
Connection: Interface with all methods for contacting a database. The connection object represents
communication context, i.e., all communication with database is through connection object only.
Statement: Encapsulates an SQL statement which is passed to the database to be parsed, compiled,
planned and executed.
ResultSet: The ResultSet represents set of rows retrieved due to query execution.
JDBC driversThe JDBC API defines the Java interfaces and classes that programmers use to connect to databases and send queries. A JDBC driver implements these interfaces and classes for a particular DBMS vendor. A Java program that uses the JDBC API loads the specified driver for a particular DBMS before it actually connects to a database. The JDBC DriverManager class then sends all JDBC API calls to the loaded driver.
The four types of JDBC drivers are: JDBC-ODBC bridge plus ODBC driver, also called Type 1.
Translates JDBC API calls into Microsoft Open Database Connectivity (ODBC) calls that are then passed to the ODBC driver. The ODBC binary code must be loaded on every client computer that uses this type of driver.
Java Database Connectivity StepsBefore we create a java jdbc connection to the database, we must first import the java.sql package. import java.sql.*; The star ( * ) indicates that all of the classes in the package java.sql are to be imported.
4. Executing a SQL statement with the Statement object, and returning a jdbc
resultSet. Statement interface defines methods that are used to interact with database via the execution of SQL statements. The Statement class has three methods for executing statements: executeQuery(), executeUpdate(), and execute(). For a SELECT statement, the method to use is executeQuery . For statements that create or modify tables, the method to use is executeUpdate. Statements that create a
table, alter a table, or drop a table are all examples of DDL statements and are executed with the method executeUpdate. execute() executes an SQL statement that is written as String object. ResultSet provides access to a table of data generated by executing a Statement. The table rows are retrieved in sequence. A ResultSet maintains a cursor pointing to its current row of data. The next() method is used to successively step through the rows of the tabular results. ResultSetMetaData Interface holds information on the types and properties of the columns in a ResultSet. It is constructed from the Connection object.
Database ConnectionsSimple four steps for create database connection: Import JDBC Packages: Add import statements in Java program to import required classes in your Java code. import java.sql.* ; // for standard JDBC programs Register JDBC Driver: This step causes the JVM to load the desired driver implementation into memory so it can fulfill your JDBC requests. Database URL Formulation: This is to create a properly formatted address that points to the database to which you wish to connect. Create Connection Object: Finally, code a call to the DriverManager object's getConnection( ) method to establish actual database connection.
JSP server
If you do not have a JSP capable web-server or application server, the first step is to download one. There are many such servers available, most of which can be downloaded for free evaluation and/or development. Some of them are: Blazix from Desiderata Software TomCat from Apache WebLogic from BEA Systems WebSphere from IBM
JSP Advantages
Separate the business logic and presentation: The logic to generate dynamic elements or content is implemented and encapsulated by using JavaBeans components. The user interface (UI) is created by using special JSP tags. This allows developers and web designers to maintain the JSP pages easily. Write Once, Run Anywhere: as a part of Java technology, JPS allows developers to developer JSP pages and deploy them in a variety of platforms, across the web servers without rewriting or changes. Dynamic elements or content produced in JSP can be served in different formats: With JSP you can write web application for web browser serving HTML format. You can even produce WML format to serve hand-held device browsers. There is no limitation of content format which JSP provides. Take advantages of Servlet API: JSP technically is a high-level abstraction of Java Servlets. It is now easier to get anything you've done with Servlet by using JSP. Beside that you can also reuse all of your Servlets you've developed so far in the new JSP.
JSP Comment
JSP comments are used to explain the complicated logic code or to mark some region inside a JSP page for later changes. Comments in JSP is declared inside a JSP page as follows: <%-- This is a JSP comment --%> <%-Multiline Comment --%>
Attributes
1.)language="java" This tells the server that the page is using the java language. Current JSP specification supports only java language. Example: <%@page language="java" %> 2.)extends="mypackage.myclass" This attribute is used when we want to extend any class. We can use comma(,) to import more than one packages. Example: <%@page language="java" import="java.sql.*,mypackage.myclass" %> 3.)session="true" When this value is true session data is available to the JSP page otherwise not. By default this value is true. Example: <%@page language="java" session="true" %> 4.)errorPage="error.jsp" errorPage is used to handle the un-handled exceptions in the page. Example: <%@page language="java" session="true" errorPage="error.jsp" %> 5.)contentType="text/html;charset=ISO-8859-1" Use this attribute to set the mime type and character set of the JSP. Example: <%@page language="java" session="true" contentType="text/html;charset=ISO-8859-1" %>
We can see declaration code is not used to produce any direct output; it is used for reusable code.
Expression
The most simple and basic of JSP scripting is expression. Expression is used to insert values directly to the output. The syntax of the expression is as follows. <?= expression ?> ** There is no space between <% and = The XML syntax of the JSP expression is as follows: <jsp:expression> Java Expression </jsp:expression>
JSP SCRIPTLETS
Syntax of JSP Scriptles are: <% // java codes %> JSP Scriptlets begins with <% and ends %> .We can embed any amount of java code in the JSP Scriptlets. JSP Engine places these code in the _jspService() method. Example : <%@page contentType="text/html" pageEncoding="UTF-8"%> <html> <head> <title>JSP syntax</title> </head> <body> <% int i=5; int j=6; int k=i+j; %> Sum of i and j = <%=k%> </body> </html> The XML syntax of JSP scriptlet is as follows: <jsp:scriptlet> // Java code of scriptlet </jsp:scriptlet>
java.lang.Object class. It represents the current JSP page. session Object : The JSP implicit session object is an instance of a java class that implements the javax.servlet.http.HttpSession interface. The Session Object provides the connection or association between the client and the server. The main use of Session Objects is for maintaining states when there are multiple page requests. application Object : This is used to share the data with all application pages. The class or the interface name of the Application object is ServletContext. The Application object is written: javax.servlet.http.ServletContext . It gives facility for a JSP page to obtain and set information about the web application in which it is running. pageContext Object : The JSP implicit pageContext object is an instance of the javax.servlet.jsp.PageContext abstract class. It provides useful context information. config Object: The config is the ServletConfig for the JSP page and has page scope. It is of type javax.servlet.ServletConfig. out Object : The out object is the object that writes into the output stream to the client. The out implicit object is used to write the output content. The JSP implicit out object is an instance of the javax.servlet.jsp.JspWriter class. exception Object : The JSP implicit exception object is an instance of the java.lang.Throwable class. It is available in JSP error pages only. .
JSP Variables
Declare a variable
Declaration of variable is storing information of data. Example : jspVar.jsp <%@ page language="java" errorPage="" %> <% String str="javatechnicalquestion.com"; int i=5; %> <html> <body> Value of String : <%=str%> Value of int variable : <%=i%> </body></html>
Array in JSP
Array is defined as the set of similar type of data in series. The Array can be String, int or character kind of datatypes.
Example : <%@ page language="java"%> <% String[] array={"C","C++","Java","Scjp","J2EE",PHP/MySql}; %> <html> <body>
<% int i=0; out.print("Array Elements are:<br>"); for(i=0;i<array.length;i++) { out.print(array[i]+"<br/>"); } %> </body> </html>
Form Validation Javascript with JSP <%@ page contentType="text/html; charset=iso-8859-1"%> <html> <head> <script> function validation() { if(document.data.user.value=="") { alert("Enter Name"); document.data.user.focus(); return false; } else if(document.data.pass.value=="") { alert("Enter Password"); document.data.pass.focus(); return false; } } </script> </head> <body> <form name="data" method="post" action="valid.jsp" onSubmit="return validation()"> <table width="100%" align=center> <tr> <td>UserName </td> <td><input type="text" name="user" /></td> </tr> <tr> <td>Password</td> <td><input type="text" name="pass" /></td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit"></td> </tr> </table> </form> </body> </html>
valid.jsp <%@ page contentType="text/html; charset=iso-8859-1"%> <% String user=request.getParameter(user); String pass= request.getParameter(pass); %> User Name : <%= user %><br> Password : <%= pass %>
Cookie
Cookie a small data file reside in user's system.Cookie created by server and sent to the client computer and cookie's value can uniquely identify a client.Cookie class reside in javax.servlet.http package.
Create Cookie :
Cookie c = new Cookie("user","value"); User and value must be String. A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.
Retrieve Cookie :
Cookie cookies [] = request.getCookies ();
Session in JSP
The session is an object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests. The session is stored on the server. <%@page contentType="text/html" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>Session Example</title> </head> <body> <form method="post" action="sess.jsp"> Name<input type="text" name="user"> Password <input type="password" name="pass"> <input type="submit" value="submit"> </form> </body> </html> sess.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> <% String s=request.getParameter("user"); String s1=request.getParameter("pass"); if(s != null && s1 != null){ session.setAttribute(user, s); } %> Welcome <%= session.getAttribute("user") %>
Destroy Session :
removeAttribute(String name) The removeAttribute method of session object is used to remove the attribute and value from the session. General syntax of removeAttribute of session object is as follows: session.removeAttribute(String) invalidate(): invalidate method of session object is used to discard the session and releases any objects stored as attributes. session.invalidate()
Chapter-6 Objectives of Project Meaning of ProjectThe meaning of project is to give physical existence to the variation brain ideas and thoughts. Project is a great source to develop technical skills in the Technical student. During the programming of the project student goes through different problems and experience. A student gets a change to climb on the roof of practical knowledge to economize to go at the fields. A very important aim of this world PROJECT consist of seven alphabets each of them has separate meaning. P for Planning Planning is good an impressive half work is done. R for RELAIABLE SOURCE Practice and theoretical material and able guidance and assistance is achieved from different sources to promote the function of planned area. O for OVERALL EXPENSES Overall expenses to provide final design to any project is also considerable. Their expenses are analyzed for each concepts and method of working on the computer. J for JOINT EFFORTS Joint efforts are much necessary for programming and result of any project. Many times some problems as books etc., are solved for external sources. E for ECONOMIC TIME FEASIBILITY It is important that the planned scheme is how much economic time feasible. It is must to analyze estimate for completion of the project. C for CONSTRUCTION After analyzing the project work is done to give logical existence of planned scheme. T for TESTING Testing of program is done before submitting the project after resting the gadget is ok for use.
Introduction to projectMatrimonial Website contains profile of the users. The project created by using JSP. The main components used are: JSP as language SQL Connectivity
The project will ask user name, user password to login for user. New users can create new account, in which he/she has to provide his/her basic details. User has facility to maintain and update his profile and can also change his password. She/he can search a best suitable match and can access her/his profile.
: : :
64-bit 4 GB 500 GB
Software Specification
OS Front End Mid End Back End Time : : : : : MS WINDOWS 7 Ultimate JSP EasyPHP-12.1 SQL Connectivity 45 days (Approx)
Human resource required (minimum): Project leader Programmer Testing Machine required Skill set : SQL Queries and EasyPHP. : : : : one one one one PC/Laptop
CONCLUSION
The project Matrimonial Site is completed, satisfying the required design specifications. This site provides a user-friendly interface. This site is developed with modular approach. Thus the site has fulfilled all the objectives identified and is able to replace the existing system. The constraints are met and overcome successfully. The system is designed as like it was decided in the design phase. This site has a user-friendly screen that enables the user to use without any inconvenience. The site provides facility to user to login and to create new accounts. This site provides the facility to find a best match for user. All modules in the site have been tested with valid data and invalid data and everything work successfully. Hence the software has proved to work efficiently.
BIBLIOGRAPHY
Google Search Engine http://www.google.com Wikipedia http://en.wikipedia.org http://www.wifiduniya.com Black Book of Java The Complete Reference J2EE by Keogh