Wednesday 27 April 2011

OPERATING SYSTEM

OPERATING SYSTEM OVERVIEW:
An operating system (OS) is an interface between hardware and user which is responsible for the management and coordination of activities and the sharing of the resources of the computer that acts as a host for computing applications run on the machine. As a host, one of the purposes of an operating system is to handle the details of the operation of the hardware. This relieves application programs from having to manage these details and makes it easier to write applications. Almost all computers (including handheld computers, desktop computers, supercomputers, video game consoles) as well as some robots, domestic appliances (dishwashers, washing machines), and portabl media players use an operating system of some type. Some of the oldest models may, however, use an embedded operating system that may be contained on a data storage device.
Operating systems offer a number of services to application programs and users. Applications access these services through application programming interfaces (APIs) or system calls. By invoking these interfaces, the application can request a service from the operating system, pass parameters, and receive the results of the operation. Users may also interact with the operating system with some kind of software user interface like typing commands by using command line interface (CLI) or using a graphical user interface (GUI, commonly pronounced “gooey”). For hand-held and desktop computers, the user interface is generally considered part of the operating system. On large multi-user systems like Unix and Unix-like systems, the user interface is generally implemented as an application program that runs outside the operating system. (Whether the user interface should be included as part of the operating system is a point of contention.)
Common contemporary operating systems include BSD, Darwin (Mac OS X), Linux, SunOS (Solaris/OpenSolaris), and Windows NT (XP/Vista/7). While servers generally run Unix or some Unix-like operating system, embedded system markets are split amongst several operating systems, although the Microsoft Windows line of operating systems has almost 90% of the client PC market.
Features :
1)GUI:
A GUI , short for graphical user interface, operating system contains graphics and icons and is commonly navigated by using a mouse.Its support makes the operating system more responsive .Examples of some GUI operating systems are Windows 98, Windows CE


2)Memory management:
Among other things, a multiprogramming operating system kernel must be responsible for managing all system memory which is currently in use by programs. This ensures that a program does not interfere with memory already used by another program. Since programs time share, each program must have independent access to memory.Various methods of memory mangement exist, including memory segmentation and paging...
3)Virtual memory:
The use of virtual memory addressing (such as paging or segmentation) means that the kernel can choose what memory each program may use at any given time, allowing the operating system to use the same memory locations for multiple tasks.
If a program tries to access memory that isn't in its current range of accessible memory, but nonetheless has been allocated to it, the kernel will be interrupted in the same way as it would if the program were to exceed its allocated memory.Under UNIX this kind of interrupt is referred to as a page fault
When the kernel detects a page fault it will generally adjust the virtual memory range of the program which triggered it, granting it access to the memory requested. This gives the kernel discretionary power over where a particular application's memory is stored, or even whether or not it has actually been allocated yet.
In modern operating systems, memory which is accessed less frequently can be temporarily stored on disk or other media to make that space available for use by other programs. This is called swapping, as an area of memory can be used by multiple programs, and what that memory area contains can be swapped or exchanged on demand.
4)Multitasking:
Multitasking refers to the running of multiple independent computer programs on the same computer; giving the appearance that it is performing the tasks at the same time. Since most computers can do at most one or two things at one time, this is generally done via time-sharing, which means that each program uses a share of the computer's time to execute.some of the multitasking os are Windows 2000, Unix
5)Multiprocessing:
An OS is capable of supporting and utilizing more tha one computer processors. below are some examples of multiprocessing operating systems are Linux,Unix,Windows 2000


Types of operating system
MS-DOS:
MS-DOS short for Microsoft Disk Operating System is an operating system for x86 based personal computers, which was purchased by Microsoft. It was the most commonly used member of the DOS family of operating systems, and was the main operating system for personal computers during the 1980s and 1990s. It was preceded by M-DOS (also called MIDAS), designed and copyrighted by Microsoft in 1979. MSDOS was written for the Intel 8086 family of microprocessors.. It was gradually replaced on consumer desktop computers by operating systems offering a graphical user interface (GUI), in particular by various generations of the Microsoft Windows operating system. MS-DOS developed out of QDOS (Quick and Dirty Operating System), also known as 86-DOS
MS-DOS development originally started in 1981, and was first released in 1982 as MS-DOS 1.0. Several versions were released under different names for different hardware. MS-DOS had eight major versions released before Microsoft stopped development in 2000. It was the key product in Microsoft's growth from a programming languages company to a diverse software development firm, providing the company with essential revenue and marketing resources. It was also the underlying basic operating system on which early versions of Windows ran as a GUI.
Features:
1).MS-DOS is an operating system designed for the IBM PC by Microsoft in 1981. 2). It was a command-line interface, meaning the user had to type in commands to use it
3).MS DOS commands were either stored as individual programs, known as external commands, or in a file called Command.com, which stored more commonly used commands. These were called internal commands eg COPY, DEL, DIR, CD and RD. 4) Several multiuser operating systems capable of running MS-DOS software.

UNIX
The UNIX operating system was designed to let a number of programmers access the computer at the same time and share its resource.The operating system controls all of the commands from all of the keyboards and all of the data being generated, and permits each user to believe he or she is the only person working on the computer.This real-time sharing of resources make UNIX one of the most powerful operating systems ever.
Although UNIX was developed by programmers for programmers, it provides an environment so powerful and flexible that it is found in businesses, sciences, academia, and industry. The Unix operating
Windows 95:
Windows 95 is a consumer-oriented graphical user interface-based operating system. It was released on August 24, 1995 by Microsoft and was a significant progression from the company's previous Windows products. During development it was referred to as Windows 4.0 or by the internal codename Chicago.
Windows 95 was intended to integrate Microsoft's formerly separate MS-DOS and Windows products. It features significant improvements over its predecessor, Windows 3.1, most visibly in the graphical user interface (GUI). There were also major changes made at lower levels of the operating system.
In the marketplace, Windows 95 was a major success, and within a year or two of its release had become the most successful operating system ever produced. It also had the effect of driving other major players in the DOS-compatible operating system out of business, something which would later be used in court against Microsoft. Some three years after introduction, Windows 95 was succeeded by Windows 98.
Windows 98:
Windows 98 (codenamed Memphis) is a graphical operating system by Microsoft. It was released on June 25, 1998, and is the successor to Windows 95. Like its predecessor, it is a hybrid 16-bit/32-bit monolithic product with an MS-DOS based boot loader. Windows 98 was succeeded by Windows Me on 14 September 2000
Windows NT:
Windows NT is a family of operating systems produced by Microsoft, the first version of which was released in July 1993. It was originally designed to be a powerful high-level-language-based, processor-independent, multiprocessing, multiuser operating system with features comparable to Unix. It was intended to complement consumer versions of Windows that were based on MS-DOS. NT was the first fully 32-bit version of Windows, whereas its consumer-oriented counterparts, Windows 3.1x and Windows 9x, were 16-bit/32-bit hybrids. Windows 2000, Windows XP, Windows Vista are based on Windows NT, although they are not branded as Windows NT.
Windows 2000:
Windows 2000 is a line of operating systems produced by Microsoft for use on business desktops, notebook computers, and servers. Released on February 17, 2000, it was the successor to Windows NT 4.0, and is the final release of Microsoft Windows to display the "Windows NT" designation. It was succeeded by Windows XP for desktop systems in October 2001 and Windows Server 2003 for servers in April 2003.
LINUX:-

Linux is a Unix-like computer operating system family, which uses the linux kernel. Linux is one of the most prominent examples of free software and open source development; typically all the underlying source cod can be freely modified, used, and redistributed by anyone. The salient features of Linux are:-
1. Linux is a true 32-bit operating system that runs on a variety of different platforms, including Intel, Sparc, Alpha, and Power-PC/
2. The interesting thing about Linux is, it is completely free!
3. Linux can and should be considered a full-blown implementation of unix. However, it can not be called "Unix"; not because of incompatibilities or lack of functionality.
4. The Linux kernel includes true multi-tasking, virtual memory, shared libraries and demand loading.
5. Provides proper memory management and TCP/IP networking.
6. Supports Multiprocessing.
7. Preemption in Linux improves latency, increasing responsiveness and making it more suitable for real-time applications.

IBM’s OS/2:-
The OS/2 operating system exploits complete capability of Intel 386 and Intel 486 technology. It is a true 32-bit, multi-threaded, multi-tasking operating system suitable for desktop as well as server applications. Its features are:-
1. It features a complete GUI for all applications including wordprocessing, printing and playing a game. In fact, one works with objects that graphically represent an activity to be performed.
2. It allows features such as managing, copying, moving, printing, deleting,opening objects through pull-down menus and/or mouse interactions.
3. For smooth runnig OS/2 needs 8 MB of RAM on the computer. However, it can work with 6 MB also.
4. It allows OS/2 program, DOS program and windows program to run in both windo session and full screen session.
5. OS/2 2.x provides DzszoS support as virtual DOS machines. The default DOS box uses a DOS Kernel that OS/2 supplies. Sos Programs can run easily under OS/2.
6. OS/2 supports Windows also in two modes: full screen and “seamless” to open the folder called windows program. In the full screen mode, Windows applications multi-task on a normal window desktop under the control of the program manager; in the seamless mode they occupy PM windows and obeys the WPS(Work Place Shell).
7. It supports threaded multitasking.
8. Since, OS/2 is fully written in C language, it is easily portable to other platforms.
9. it has weaknesses in the area of performance stability, and ease of use.





APPLE’S OS:-

The operating system on MAC is almost 11 years old,however,
Features such as 32 bit addressing and colour matching are only now appearing in Windows. The Mac OS 8, which was introduced in 1984has th following salient features:-
1. New multi-tasking Finder lets you copy large files while you launch applications or open document. The new Finder also features Pop-up windows that keep files handy.
2. The Internet Setup Assistant helps you get online in minutes, allowing you to connect to, explore, and publish on the web, using your choice of popular browsers.
3. Publish a personal Web site in just a few easy steps.
4. Views, open and edit Window files within the Mac OS.
5. Enjoy the magic of multimedia, including virtual reality scenes, 3D graphics, full screen video, digital music, and more.
6. Run Java software directly from your desktop rather than through a web browser.






























LINUX COMMANDS
1)ls: Listing files
This command is used to list the files in the current directory. The files are arranged according to the ASCII collating sequence i.e first white spaces,then numerals,then upper case letters,and then lower case letters,
$ls[enter]
Aadt
Aady
Chap01
Cmdo
Dir1

ls command is used with many options:
OPTION FUNCTION
x
r
a
l
t
i
c
Displays multicolumnar output
Recursively lists all files
Shows all hidden files
Long listing showing 7 file attributes
Sorts by last modification time
Shows inode number
Sorts by last inode change


2)cat: Creating and opening files
Opens the specified file else creates one. It can take more than one file name as an argument
$cat foo[enter]
Kljdkfs;ma #here foo which was present has been opened

$cat foo1[enter]
wlejq
aqmwek
[ctrl-d] #here foo1 has been created

3)cp: Copying files
It copies a file or a group of files. To copy more than one file to a destination,the destination should be a directory and should be present,the cp command won’t create the directory if not present.
$cp chap01 chap02[enter]
Copies chap01 to file chap02

$cp chap01 chap02 dir2
Copies 2 files to dir2 directory

4)mv: Moving files
It is similar to cp command except that the source file now gets removed
$mv c1 c2[enter]
$cat c1[enter]
c1:no such file found

5)dir: Directory command
Shows all directories in the current directory
$dir[enter]
dir1
dir2
dir2

6)Logging in:
The login prompt indicates that this terminal is available for some user to login. At this prompt enter the user name as provided by the administrator and then we’ll get a password prompt.enter the password and press enter. If successful a login string prompt $ appears
login:user1[enter]
password:*******[enter]
$_

7)Logging out:
To end the current session and logout you can type either logout or exit followed by an enter.this terminal is then used for others to use
$logout[enter]
or
$exit[enter]

8)date:Display system date and time
$date[enter]
Sat feb 11 12:10:34 EST 2000
This command can also be used with format specifiers as arguments each preceeded by a + and %
d-day of the month(1 to 31)
y-last 2 digits of the year
H,M,S-hour,minute, second respectively
m-month number
h-name of the month

$date +%m[enter]
11



9)cal: the calendar
Lets one see the calendar of a particular month or year.to see that of a month you need to specify its 3 letter abbreviation as argument
$cal dec 2000


December 2000
su mo tu we th fr sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
10)clear: clearing screen
$clear[enter]
This clears the screen

11)pwd: Present working directory
This command outputs the current directory of the user in absolute path form
$pwd
/home/user2

12)rm: Removing files
This is used in a simlar way as mv and cp.an important thing to note is that it can also delete non empty directories
$rm foo[enter]
Deletes file foo

13)echo:
Echoes the string on the console
$echo hello[enter]
hello
$echo “hiiii”[enter]
hiiii

14)bc: the calculator
It belongs to the family of commands called filters that expect input from users when used without argument
$bc[enter]
12+5[enter]
17
15)mkdir: Making directory
This creates a directory as
$mkdir docs[enter]
Directory docs created

16)rmdir: Deleting directory
This deletes a directory but it should be empty
$rmdir docs[enter]
Docs has been deleted

17)the vi editor:
it is a full screen editor that is used for editing files. A vi session begins by invoking vi with a file name. we get a screen with tids on 24 out of 25 lines and the file name at the end.
$vi foo[enter]
~
~
~
~
~
~
~
~
~
“foo.text”

Vi works in the modes:
1)command mode:here keys are used as commands to act on text
2)input mode:here any key depressed is entered as text
3)last line mode:here commands are entered on the last line to act on text

Commands
1) :w[enter]:saves file and remains in editing mode

2) :q[enter]:saves file and quits editing mode

3) :x[enter]:quits editing mode without changes being saved

4) i: inserts text at the left of cursor as

the vi editor
ifull-screen editor[esc]
the vi full-screen editor

5) [ctrl-d]:scrolls half page forward

6) [ctrl-u]:scrolls half page backwards

7) [ctrl-f]:scrolls full page forward

8) [ctrl-b]:scrolls full page backwards

9) x:deletes a character under cursor


hello world
x
hello word






10) dd:deletes the current line

hi my name is
i study in standard
today is my b’day
dd
hi my name is
today is my b’day


11) dw:deletes current word

hello world
dw
world




















INSTALLING WINDOWS XP:

Step 1 - Start your PC and place your Windows XP CD in your CD/DVD-ROM drive. Your PC should automatically detect the CD and you will get a message saying "Press any key to boot from CD". Soon as computer starts booting from the CD your will get the following screen:
Step 2 - At this stage it will ask you to press F6 if you want to install a third party Raid or SCSI driver. If you are using a an IDE Hard Drive then you do not need to press F6. If you are using a SCSI or SATA Hard drive then you must press F6 otherwise Windows will not detect your Hard Drive during the installation. Please make sure you have the Raid drivers on a floppy disk. Normally the drivers are supplied on a CD which you can copy to a floppy disk ready to be installed. If you are not sure how to do this then please read your motherboard manuals for more information.
Step 3 - Press S to Specify that you want to install additional device.
Step 4 - You will be asked to insert the floppy disk with the Raid or SCSI drivers. Press enter after you have inserted the disk.
Step 5 - You will see a list of Raid drivers for your HDD. Select the correct driver for your device and press enter.
Step 6 - You will then get a Windows XP Professional Setup screen. You have the option to do a new Windows install, Repair previous install or quit. Since we are doing a new install we just press Enter to continue.
Step 7 - You will be presented with the End User Licensing Agreement. Press F8 to accept and continue
Step 8 - This step is very important. Here we will create the partition where Windows will be installed. If you have a brand new unformatted drive you will get a screen similar to below. In our case the drive size is 8190MB. We can choose to install Windows in this drive without creating a partition, hence use the entire size of the drive. If you wish to do this you can just press enter and Windows will automatically partition and format the drive as one large drive.
However for this demonstration I will create two partition. The first partition will be 6000MB (C: drive) and second partition would be 2180MB (E: drive). By creating two partition we can have one which stores Windows and Applications and the other which stores our data. So in the future if anything goes wrong with our Windows install such as virus or spyware we can re-install Windows on C: drive and our data on E: drive will not be touched. Please note you can choose whatever size partition your like. For example if you have 500GB hard drive you can have two partition of 250GB each.Press C to create a partition.
Step 9 - Windows will show the total size of the hard drive and ask you how much you want to allocate for the partition you are about to create. I will choose 6000MB. You will then get the screen below. Notice it shows C: Partition 1 followed by the size 6000 MB. This indicates the partition has been created. We still have an unpartitioned space of 2189MB. Next heighlight the unpartitioned space by pressing down the arrow key. Then press C to create another partition. You will see the total space available for the new partition. Just choose all the space left over, in our case 2180MB.
Step 10 - Now you will see both partition listed. Partition 1 (C: Drive) 6000MB and Partition 2 (E: Drive) 2180MB. You will also have 8MB of unpartitioned space. Don't worry about that. Just leave it how its is. Windows normally has some unpartitioned space. You might wonder what happened to D: drive. Windows has automatically allocated D: drive to CD/DVD-ROM.
Select Partition 1 (C: Drive) and press Enter.
Step 11 - Choose format the partition using NTFS file system.This is the recommended file system. If the hard drive has been formatted before then you can choose quick NTFS format. We chose NTFS because it offers many security features, supports larger drive size, and bigger size files.Windows will now start formatting drive C: and start copying setup files
step 12 - After the setup has completed copying the files the computer will restart. Leave the XP CD in the drive but this time DO NOT press any key when the message "Press any key to boot from CD" is displayed. In few seconds setup will continue. Windows XP Setup wizard will guide you through the setup process of gathering information about your computer.
Step 13 - Choose your region and language.
Step 14 - Type in your name and organization.
Step 15. Enter your product key.
Step 16 - Name the computer, and enter an Administrator password. Don't forget to write down your Administrator password.
Step 17 - Enter the correct date, time and choose your time zone.
Step 18 - For the network setting choose typical and press next
.Step 19 - Choose workgroup or domain name. If you are not a member of a domain then leave the default settings and press next. Windows will restart again and adjust the display.
step 20 - Finally Windows will start and present you with a Welcome screen. Click next to continue.
Step 21 - Choose 'help protect my PC by turning on automatic updates now' and press next
Step 22 - Will this computer connect to the internet directly, or through a network? If you are connected to a router or LAN then choose: 'Yes, this computer will connect through a local area network or home network'. If you have dial up modem choose: 'No, this computer will connect directly to the internet'. Then click Next.
Step 23 - Ready to activate Windows? Choose yes if you wish to active Windows over the internet now. Choose no if you want to activate Windows at a later stage.
Step 24 - Add users that will sign on to this computer and click next.
Step 25 - You will get a Thank you screen to confirm setup is complete. Click finish.
Step 26. Log in, to your PC for the first time.
step 27 - You now need to check the device manager to confirm that all the drivers has been loaded or if there are any conflicts. From the start menu select Start -> Settings -> Control Panel. Click on the System icon and then from the System Properties window select the Hardware tab, then click on Device Manager.If there are any yellow exclamation mark "!" next to any of the listed device, it means that no drivers or incorrect drivers has been loaded for that device. In our case we have a Video Controller (VGA card) which has no drivers installed.
Your hardware should come with manufacturer supplied drivers. You need to install these drivers using the automatic setup program provided by the manufacturer or you need to manually install these drivers. If you do not have the drivers, check the manufacturers website to download them.



SHELL SCRIPTS

// Write a shell script to print the sum of all digits of a given number e.g. sum of digits of no. 123 is 1+2+3=6//

echo"enter number"
read n
quot=$n
sum=0
while[$quot-ne 0]
do
let rem=quot %10
let sum=sum + rem
let quot =quot / 10
done
echo "sum=$sum"

EXECUTION STEP :
$ chmod +r digsum
$sh digsum

OUTPUT:

Enter the number:234
Sum=9


// Shell script to print reverse of a number

echo"enter the number"
read n
rev=0
sd=0

while [ $n -gt 0 ]
do
let sd= n % 10
let rev= rev * 10 + sd
let n= n / 10
done
echo "Reverse number is $rev"


EXECUTION STEP :
$ chmod +r reverse
$sh reverse

OUTPUT :
enter the number 234
Reverse number is 432

// Shell script to convert file contents from lower case to upper case

echo"enter the source file name:"
read sfname

echo"enter the target file name:"
read tfname

cat $sfname|"[a-z]""[A-Z]">$tfname


EXECUTION STEP :
$ chmod +r upper
$sh upper

OUTPUT :
enter the source file name:rar
enter the target file name:res
TARDE:INFORMATION TECHNOLOGY

// Develop a shell script to compare three numbers and print the largest given numbers from command line


echo"enter the numbers:"
read a
read b
read c
if[$a-gt$b]&&[$a-gt$c]
then
echo"largest number is $a"
elif[$b-gt$c]
then
echo"largest number is $b"
else
echo"largest number is $c"
fi



Output:
$sh large
enter the numbers:
5
4
3
largest number is 5

// Shell script to generate fibonacci series
echo"enter the number upto which series is to be generated"
read n
a=0
b=1
echo $a
echo $b

for(( i=2 ;i<=n;i++))
do
let c=a+b
echo “$c “
let a=b
let b=c
done


EXECUTION STEP :
$ chmod +r fibbo
$sh fibbo

OUTPUT :
enter the number upto which series is to be generated:10
0
1
1
2
3
5
8
13
21
34

// Shell script to check whether a number is prime or not//

echo enter a number
read num
for(( i=2;i<=n;i++))
do
if [ `expr $num % $i` -eq 0 ]
then
echo $num is not prime
echo since it is divisible by $i
exit
fi

done
echo $num is a prime number

EXECUTION STEP :
$ chmod +r prime
$sh prime

OUTPUT :

1) enter a number
15
15 is not a prime number
since it is divisible by 3

2) enter a number
13
13 is a prime number
// Shell script to find factorial of a number//

echo “Enter the number:”
read n

fact=1
for(( i=1;i<=n;i++))
do
let fact = fact*i

done

echo “The factorial of $n is: $fact”


EXECUTION STEP :
$ chmod +r factorial
$sh factorial

OUTPUT :
Enter the number: 5
The factorial of 5 is: 120
























// Shell script to create table of a number//

echo “Enter the number:”
read n

for(( i=1;i<=10;i++))
do
let tab= num*i
echo “$tab”

done



EXECUTION STEP :
$ chmod +r table
$sh table

OUTPUT :
Enter the number: 5
5
10
15
20
25
30
35
40
45
50

JAVA LAB MANUAL

PROGRAM TO SHOW VALIDATION OF USER USING SERVLET  

RequestServlet.java
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.sql.*;
public class RequestServlet extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
            {
                        res.setContentType("text/html");
                        PrintWriter out=res.getWriter();
                        out.println("<html><body>");
                        String name=req.getParameter("name");
                        String pass=req.getParameter("pass");
                        if(name.equals("ABCDE")&& pass.equals("123456"))
                                    out.println("user is valid through service method");
                        else
                                    out.println("user is invalid through service method");
                        out.println("</body></html>");
            }
            

PROGRAM TO DISPLAY MESSAGE ON BROWSER  USING JSP


Init.jsp

<html>
<body>
<%!
            String s;
            public void jspInit()
            {
                        ServletConfig con=getServletConfig();
                        s=con.getInitParameter("name");
            }
%>

<%
            String s1=config.getInitParameter("name");
            out.println(s+s1);
%>
</body>
</html>


Web.xml

<web-app>
<servlet>
<servlet-name>my</servlet-name>
<jsp-file>Init.jsp</jsp-file>
<init-param>
<param-name>name</param-name>
<param-value> i miss you</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>my</servlet-name>
<url-pattern>/run</url-pattern>
</servlet-mapping>
</web-app>
</body>
</html>




public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
            {           
                           res.setContentType("text/html");
                        PrintWriter out=res.getWriter();
                        out.println("<html><body>");
                        String name=req.getParameter("name");
                        String pass=req.getParameter("pass");
                        if(name.equals("ABCDE")&& pass.equals("123456"))
                                    out.println("user is valid through get method");
                        else
                                    out.println("user is invalid through get mathod");
                        out.println("</body></html>");
                       
            }
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
            {
                        res.setContentType("text/html");
                        PrintWriter out=res.getWriter();
                        out.println("<html><body>");
                        String name=req.getParameter("name");
                        String pass=req.getParameter("pass");
                        if(name.equals("ABCDE")&& pass.equals("123456"))
                                    out.println("user is valid through get method");
                        else
                                    out.println("user is invalid through get mathod");
                        out.println("</body></html>");
            }
}


Login.html

<html>
<body>
<form action="run3" method="get">
enter your name:
<input type="text" name="name"/>
<br>
enter your password:
<input type="password" name="pass"/>
<br>
<input type="submit"/>
</body>
</html>

Web.xml
<web-app>
<servlet>
<servlet-name>RequestServlet</servlet-name>
<servlet-class>RequestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RequestServlet</servlet-name>
<url-pattern>/run3</url-pattern>
</servlet-mapping>
</web-app>


PROGRAM TO INSERT DATA INTO TABLE USING JSP



import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class TestDB1
{
public static void main(String ss[])
     {
          try
           {
                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection c=DriverManager.getConnection("jdbc:odbc:mydsn","system","mca6");
                String t1="China";
                int t2=422;
                Statement s=c.createStatement();
                s.executeUpdate("INSERT INTO emp " + "VALUES ('chinaaaaaaa',200000001)");
                ResultSet result1=s.executeQuery("SELECT * FROM emp");
                while(result1.next())
                {
                System.out.println("name : "+result1.getString(1));
                System.out.println("salary : "+result1.getString(2));
                }
                System.out.println("after insertion");
                                                               
                                                               
          }
catch(SQLException e)
         {
                e.printStackTrace();
         }
catch(Exception i)
        {
             System.out.println(i);
        }
   }
}          



PROGRAM OF CALLING ONE SERVLET BY ANOTHER SERVLET


RequestDispatcher2.java

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class RequestDispatcher2 extends HttpServlet
{
            public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
            {
                        res.setContentType("text/html");
                        PrintWriter out=res.getWriter();
                        out.println("<html><body>");
                        String s="before dispatcher";
                        out.println(s);
                        try
                        {
                                   
                                    RequestDispatcher rd=req.getRequestDispatcher("/run2");
                                    rd.include(req,res);
                                   
                        }
                        catch(Exception e)
                        {
                                    out.println("exception");
                        }
                        out.println("after dispatcher");
                        out.println("</body></html>");
            }
}
           









DemoServlet2.java

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class DemoServlet2 extends GenericServlet
{
            public void service(ServletRequest req, ServletResponse res)throws ServletException,IOException
            {
                        res.setContentType("text/html");
                        PrintWriter out=res.getWriter();
                        out.println("<html><body>");
                        out.println("hello servlet with GenericServlet");
                        out.println("</body></html>");
            }
}



Web.xml

<web-app>
<servlet>
<servlet-name>RequestDispatcher2</servlet-name>
<servlet-class>RequestDispatcher2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RequestDispatcher2</servlet-name>
<url-pattern>/run7</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DemoServlet2</servlet-name>
<servlet-class>DemoServlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DemoServlet2</servlet-name>
<url-pattern>/run2</url-pattern>
</servlet-mapping>
</web-app>


PROGRAM TO SHOW VALIDATION OF USER USING JSP


Parameter.jsp

<%
            String name=request.getParameter("name");
            String pass=request.getParameter("pass");
            RequestDispatcher rd=request.getRequestDispatcher("Demo.jsp");
            rd.include(request,response);
            if(name.equals("DUCAT")&& pass.equals("DUCAT"))
                                    out.println("user is valid through jsp parameter");
            else
                        out.println("user is invalid through jsp parameter");
%>      

           

Index.jsp

<html>
<body>
<form action="Parameter.jsp">
enter your name:
<input type="text" name="name">
<br>
enter your password:
<input type="password" name="pass"/>
<br>
<input type="submit"/>
</body>
</html>

Demo.jsp

<%out.println("hello jsp");%>

Web.xml

<web-app>
</web-app>

PROGRAM TO DEMONSTRATE USE OF BEANS


MyBean.java

package my;
public class MyBean
{
            private String name;
            private int pass;
            public void setName(String name)
            {
                        this.name=name;
            }
            public void setPass(int pass)
            {
                        this.pass=pass;
            }
            public String getName()
            {
                        return name;
            }
            public int getPass()
            {
                        return pass;
            }
           
            public String validate()
            {
            try
            {
                        if(name.equals("kapil"))
                                    return "valid";
            }
            catch(Exception e){}
            return "invalid";
            }
           
            public int add(int x,int y)
            {
                        return x+y;
            }
}
Bean.jsp
<%
            String name=request.getParameter("name");
            String pass=request.getParameter("pass");
%>

<jsp:useBean id="t1" class="my.MyBean"/>
<jsp:setProperty name="t1" property="name" param="name"/>
<jsp:setProperty name="t1" property="pass" param="pass"/>

<%
            String s=t1.validate();
            int r=t1.add(10,20);
            out.println(s+r);
%>

<jsp:getProperty name="t1" property="name"/>
<jsp:getProperty name="t1" property="pass"/>

Index.jsp

<html>
<body>
<form action="Bean.jsp">
enter your name:
<input type="text" name="name">
<br>
enter your password:
<input type="password" name="pass"/>
<br>
<input type="submit"/>
</body>
</html>

Web.xml

<web-app>
</web-app>


                                             PROGRAM TO SET SCOPE OF BEANS

MyBean.java

package my;
public class MyBean
{
            private String name;
            private int pass;
            public void setName(String name)
            {
                        this.name=name;
            }
            public void setPass(int pass)
            {
                        this.pass=pass;
            }
            public String getName()
            {
                        return name;
            }
            public int getPass()
            {
                        return pass;
            }
           
            public String validate()
            {
            try
            {
                        if(name.equals("ducat"))
                                    return "valid";
            }
            catch(Exception e){}
            return "invalid";
            }
           
            public int add(int x,int y)
            {
                        return x+y;
            }
}


Bean.jsp

<jsp:useBean id="t1" class="my.MyBean" scope="session"/>
<jsp:setProperty name="t1" property="*" param="name"/>

<%
            String s=t1.validate();
            int r=t1.add(10,20);
            out.println(s+r);
%>

<jsp:getProperty name="t1" property="name"/>
<jsp:getProperty name="t1" property="pass"/>

Index.jsp

<html>
<body>
<form action="Bean.jsp">
enter your name:
<input type="text" name="name">
<br>
enter your password:
<input type="password" name="pass"/>
<br>
<input type="submit"/>
</body>
</html>

PROGRAM TO DEMONSTRATE WORKING OF RMI



MyServer.java

package my;
import java.rmi.*;
import java.rmi.server.*;
public class MyServer extends UnicastRemoteObject implements MyRemote
{
            public MyServer() throws RemoteException
            {}
            public int add(int x,int y)throws RemoteException
            {
                        return(x+y);
            }
}


Register.java

package my;
import java.rmi.*;
import java.rmi.server.*;
public class Register
{
            public static void main(String s[])
            {
                        try
                        {
                                    my.MyServer m=new my.MyServer();
                                    Naming.rebind("ducat",m);
                        }
                        catch(Exception e)
                        {
                                    System.out.println(e);
                        }
            }
}




MyRemote.java

package my;
import java.rmi.*;
public interface MyRemote extends Remote
{
            public int add(int x,int y)throws RemoteException;
}

Remote.java

import my.*;
import java.rmi.*;
import java.rmi.server.*;
public class Client
{
            public static void main(String s[])
            {
                        try
                        {
                                    my.MyRemote m=(my.MyRemote)Naming.lookup("rmi://localhost:1099/ducat");
                                    System.out.println(m.add(10,20));
                        }
                        catch(Exception e)
                        {
                                    System.out.println(e);
                        }
            }