Professional Documents
Culture Documents
Ajp All Practicals
Ajp All Practicals
Ajp All Practicals
Class CO5I-C
Experiment No 1
Title of Experiment Write the program to demonstrate the use of AWT component.
Experiment-1
Program code :
Import.java.awt.*;
Class Exp1
{
Public static void main(String args[])
{
Frame f= new Frame();
f.setVisible(true);
f.setSize(400,400);
f.setLayout(new FlowLayout());
f.setTitle(“Experiment no.1”); Label
l1=new Label(“Welcome to Java”);
f.add(1);
1
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
`
}
}
OutPut:
Program code:
import.java.awt.*; class
Expt1
{
Public static void main(String args[])
{
Frame f= new Frame();
f.setVisible(true);
f.setSize(400,400);
f.setLayout(new FlowLayout());
f.setTitle(“Experiment no.1”);
2
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
`
Checkbox c1=new Checkbox(“Marathi”);
Checkbox c2=new Checkbox(“English”);
Checkbox c3=new Checkbox(“Hindi”);
Checkbox c4=new Checkbox(“Sanskrit”);
f.add(c1);
f.add(c2);
f.add(c3);
f.add(c4);
}
}
Output:
3. Write a program to create three Buttons with Caption Ok, Reset and Cancel.
Program code:
import.java.awt.*; class
Expt1
3
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
`
{
Public static void main(String args[])
{
f.setLayout(new FlowLayout());
f,setTitle(“Experiment no.1”); Button
b1=new Button(“OK”);
Button b2=new Button(“RESET”);
Button b3=new
Button(“CANCEL”); f.add(b1);
f.add(b2);
f.add(b3);
}
}
Output:
4
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
1 Radio buttons aíe used when we need to pick a single A checkbox authoíises us to choose one oí
option out of vaíious available alteínatives. moíe options.
2
Heíe we use an HľML <input> tag and set the íadio as We use the HľML <input> tag followed by
a type attíibute. the checkbox attíibute.
4
When we need to íestíict the useí’s selection to just It is opeíated when we need to peímit the
one option, then we use it. useí to choose multiple options.
5
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
Dated signature of
Marks Obtained
Teacher
6
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Experiment-2
Ans
Program code:
import java.awt.*;
import java.applet.*;
/*
1
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
L.add(“Mumbai”);
L.add(“Pune”);
L.add(“Delhi”);
L.add(“Hydrabad”);
L.add(“Bengaluru”);
L.add(“Chennai”);
L.add(“Kolkata”);
L.add(“Ahemdabad”);
L.add(“Amritsar”);
L.add(“Agra”);
Add(L);
Output:
2
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Ans.
Program code:
import java.awt.*;
import java.applet.*;
/*
3
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
{
L.add(“Lokmat”);
L.add(“Sakal”);
Output:
4
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
Practical Relates Questions
1. Write the name of components used in following output.
Ans.
Ans.
5
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
i. getSelectedItem()
ii. getSelectedIndex()
6
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Experiment-3
Ans.
Program code:
{
public static void main(String args[])
1
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
{
Frame f=new Frame();
f.setVisible(true);
f.setSize(500,500);
f.setLayout(new GridLayout(3,2));
Button b1=new Button(“Button1”);
Button(“Button5”);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
}
}
Output:
2
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Ans.
Program code:
Import java.awt.*;
Class R
3
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
public static void main(String args[])
f.setVisible(true);
f.setSize(500,500);
b2=new Button(“South”);
f.add(b1,BorderLayout.NORTH);
f.add(b2,BorderLayout.SOUTH);
f.add(b3,BorderLayout.EAST);
f.add(b4,BorderLayout.WEST);
f.add(b5,BorderLayout.CENTER);
Output:
4
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
BorderLayout.WEST iv.
BorderLayout.NORTH
v. BorderLayout.SOUTH
5
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
3. Write the default horizontal and vertical gap in flowLayout.
Ans. The default horizontal and vertical gap will be 5 pixels
6
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Experiment-4
Ans.
Program code.
1
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
Import java.awt.Button;
Import java.awt.GridBagConstraints;
Import java.awt.GridBagLayout;
Import javax.swing.*;
Public GridBagLayoutExample(){
GridBagConstraints(); setLayout(grid);
GridBagConstraints.HORIZONTAL; gbc.gridx=0;
gbc.gridy=0; this.add(new
= GridBagConsstraints.HORIZONTAL; gbc.ipady =
2
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
gbc.gridy =1; this.add(new Button(“Button
GridBagConstraints.HORIZONTAL;
gbc.gridwidth = 2; this.ad(new
Button(“Button Five”),gbc);
setSize(300,300);
setPreferredSize(getSize()); setVisible(true);
Output:
3
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
4
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Ans.
Program code:
Import java.awt.*;
{
GridBagLayoutExample()
add(t); add(c);
add(ta); add(bs);
5
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
class GridBagLayoutJavaExamplel
GridBagLayoutExample(); frame.setTitle(“GridBagLayout in
frame.setVisible(true);
Output:
6
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
Practical Relates Questions
1. State difference between GridLayout and GridBagLayout.
Ans
Ans.
GridBagLayout class is a flexible layout manager. It is used to aligns the components
horizontally, vertically, or along their baseline. It doesn’t require the components of the same
size. Each GridBagLayout object manages a rectangular grid of cells, dynamic with each
component occupying one or more cells, called its display area. GridBagLayout components
are associated with the instance of GridBagConstraints. These constraints are used to define the
component’s display area and their positions. In addition to its constraints object, the
GridBagLayout also considers each component’s minimum and preferred sizes in order to
7
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
`
determine a component’s size. GridBagLayout components are also arranged in the rectangular
grid but can have different sizes and can occupy the multiple rows or columns. Constructor:
GridBagLayout(): It is used to creates a grid bag layout manager.
8
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Experiment-5
Import java.awt.*;
Import java.awt.evemt.*;
MenuBar mb;
MenuItem m1,m2,m3,m4;
MenuShortcut ms;
MenuDemo1()
setTItle(“MenuBar Demo”);
setSize(500,500); setLayout(null);
1
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
ms=new
MenuShortcut(KeyEvent.VK_X);
MenuBar();
m1=new MenuItem(“New…,”);
m2=new MenuItem(“Open..,”);
m3=new MenuItem(“Save
As..”); m4=new
MenuItem(“Exit”,Ms);
ma.add(m1); mn.add(m2);
mn.addd(m3);
mn.addSeperator();
mn.add(m4); mb.add(mn);
md.setVisible(true);
2
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Import java.awt.evemt.*;
MenuBar mb;
MenuItem m1,m2,m3,m4;
MenuShortcut ms;
MenuDemo1()
3
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
setTItle(“MenuBar Demo”);
MenuShortcut(KeyEvent.VK_X); mn=new
Menu(“File”):
m2=new
MenuItem(“Open..”); m3=new
MenuItem(“Exit”,ms);mn.add(m1)
mn.add(m2); mn.addd(m3);
md.setVisible(true); } }
Output:
4
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Ans.
5
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
iv. JmenuIt
em.setMnemonic(KeyEvent. VK_N) – A set keyboard shortcut to a
menu item
mnuNew.setMnemonic(KeyEvent.VK_N);
VK N: ALT+n
Ans. Syntax :
6
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Experiment 6
1. Write a program to develop a frame to select the different states of India using
JComboBox.
Ans.
Program code:
Import javax.swing.*;
Aaa(){
f.add(cb); f,setLayou(null);
f.setSize(400,400);
f.setVisible(true);
1
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
{new Aaa();}
Output:
Import java.awt.*;
2
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
f.setSize(500,500);
f.setVisible(true);
f.setDefaultCloseOperation(J/frame.EXIT_ON_CLOSE);
S1.setHorinzontalScrooBarane.HORIZONTAL_SCROLLBAR_ALWAYS);
S1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
F.getContentPane(). Add(s1);
Javax.swing.SwingUtilities.invokeLater(new Runnable() {
Scroll();
}}; } }
Output:
3
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Ans.
4
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Ans.
Ans. getContentPane()
In java Swing, the layer that is used to hold objects is called the
fcontent pane. The getContentPane() method retrieves the content pane
layer so the you can add an object to it The content pane is an object
created by the Java run time environment.
5
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
6
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Experiment No 7
Experiment 7
1. Write a Jtree program to show root directory and its subFolders of your Systems.
Ans.
Program code:
Import java.io.*:
System.out.println(roots[i].toString());
} } } */
//importing classes/files
Import java.io*;
Import java.io.File;
Class Main{
1
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
// main
driver code
{ try
if(file.isDirectory()) {
System.out.println{
“directory:”+ file.getCanonicalPath()};
displayDirectory(file);
System.out.println{
“file:”+ file.getCanonicalPath()};
} }
Catch(IOException e) {
e.printStackTrace();
} } }
2
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Output:
ans.
ii. It has a root node at the top most which is apparent for all nofres in
the tree.
3
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Ans.
Import javax.swing.JTree;
4
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Experiment No.10
1. Develop a program to accept two numbers and display product of two numbers
when user pressed ”Multiply” button.
Ans.
Program code:
Import java.awt.*;
Import java.awt.event.*;
Public class Exp10 extends Frame implements ActionListener
{
Label l1, l2, l3;
Textfield tf1;
Int num1, num2;
Exp10(int n1, int n2)
{ setSize(400,400); setLayout(
new FlowLayout()); setVisible(true);
num1=n1;
num2=n2; l1=new
Label(“num1:”+n1); l2= new
Label(“num2:” +n2);
1
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
Add(l1);
Add(l1);
Add(l1);
Add(l1)
Add(l2);
Add(b1);
Add(tf1);
B1.addActionListener(this);
}
Public void actionPerformed(ActionEvrent e) // overriding the keyPressed() method
of Keylistener interface
{
Tf1.setText(“Multication is:” +num1*num2);
}
Public static vpoid main(String[][ args)
{
New Exp10(12,13);
} }
Output:
2
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
3
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
setLayout(null);
setVisible(true); l
= new Label();
l.setBounds (20, 50, 100, 20);
area = new TextArea();
area.adKeyListener(this);
add(l); add(area);
}
Public void keyPressed (KeyEvent e) //overriding the keypressed()
method of KeyListener interface { l.setText (“Key Pressed”);
}
Public void keyReleased (KeyEvent e) //overriding the keyReleased()
method of KeyListener interface
{ l.setText(“Key Released”);
}
Public void keyTyped (keyEvent e) // overriding the keyTyped() method of
Keylistener interface
{
}
Public static void main(String[] args)
{
New Expt10();
}
}
4
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
i.
Event:- Event is an object that describes state chage in a source.
Event may also occur that are not directly caused by
interactions with the UI.
Applet are event driven programs. Tjere are several types of events. ii.
Event Sources:- A source is an object that generates an event. Sources may
generate more than one type of event. A source must registr listeners I
order for the listeners to receive notification about specific type of event.
Each type of event has its own registration method. iii. Event Listener:- A
listener is an object that is notified when an event occurs. It has two major
requirements. It must registered with one or more Sources to receive
notification about specific type of events.
4. List various methods of ActionListener interface.
Ans. Method in ActionListener interface
i. Void actionPeerformed(ActionEvent e) Invoked when an
action occurs.
5
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22517)
Practical Answer Sheet
6
Name of Student Swati Padhi
Roll No. 20203C0038
Class CO5I-C
Experiment No 11
Title of Experiment Write a program to demonstrate various mouse events using
MouseListener and MouseMotion listener interface.
Experiment-11
1. Write a program to change the background color of Applet when user performs events
using Mouse.
Ans.
Import java.applet.*;
Import java.awt.*;
Import java.awt.event.*;
{
addMouseListener(this);
{
setBackgrounf(Color.YELLOW);
{
}
Public void mouseExitedd(MouseEvent e)
{
}
{
}
Output:
2. Write a program to count the number of clicks performed by the user in a Frane window.
Ans.
Label l;
public void init()
l.setBounds(50,150,200,100); add(l);
l.setText("Mouse Entered");
l.setText("Mouse exited");
}
public void mouseClicked(MouseEvent e)
}
3. Write a program to demonstrate the use o f mouse Dragged and mouseMoved method of
MouseMotionListener.
Ans.
Import java.awt.*;
Import java.awt.event.*;
Import java.applet.*;
/*<applet code=”MouseMotionEventTest.class” height=300 width=300></applet>*/
repaint();
}
Public void mouseMoved(MouseEvent me)
{
showStatus(“Moving mouse at”+me.getX()+”,”+me.getY());
}
Public void paint (Graphics g)
{
g.drawString(msg, mouseX, mouseY);
}
}
Output:
Ans. There are five types of event that MouseListener can generate:
2. Void mouseMoved(MouseEvent e):Invoked when the mouse cursor is moved from one
point to another within the component, without pressing any mouse buttons.
2. Do all componets generate the MouseEvent
Ans. The coordinates of the mouse when ever a click takes place can be found by detecting the
click event with an event listener and finding the event’s x and y position.
Marks
Dated signature of
arks Obtained Teacher
Process Product
Related(35) Related(15) Total(50)
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
7
Name of Student Swati Padhi
Roll No. 20203C0038
Class CO5I-C
Experiment No 12
Title of Experiment Write a program to demonstrate the use of JTextField and
JPasswordField using Listener Interface.
Experiment-12
1. Write a program using JPasswordField and JTextField to demonstrate the use of user authentication.
Ans.
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
Public class A extends JFrame implements ActionListener
{
JButton nutton;
JTextField jtf;
JPasswodField jpf;
JLabel j1, j2;
Public A()
{
setVisible(true);
setTitle(“MyFrame”);
setSize(300,300); setLayout(new FlowLayout());
j1=new
JLabel(“User Name”); j2=new
JLabel(“Password”); jtf= new
JTextField(15); button = new
JButton(“Submit”); add(j1);
add(jtf); add(j2); add(jpf);
add(button);
button.addActionListener(this);
}
Public void actionPerformed(ActionEvent e)
{
String s1,s2;
S1= jtf.getText();
S2=jpf.getText();
If(s1.equals(“Prakash Koyander””)&&(s2.equals(“123”)))
{
JOptionPane.showMessageDialog(this, “Authenticated User”);
}
Else
{
JOprionPane.show MessageDialog(this, “Unauthorized User”);
}
Pubic static void main(String[] args)
{
A frame2 = new A();
}
}
Output:
3. Write a program using JPassworField to accept password from user and if the length is less
tha 6 characters then error message should be displayed “Password length must be > 6
characters”. Ans.
});
});
frame.pack();
frame.setVisible(tru e);
}
}
Output:
3. Which component can be used to accept the multiline input from user.
Ans. The JTextArea class provides a component that displauys multiple lines of text and optionally
allows the user to edit the text. If you need to obtain only one line of input from the user, you
should use a text field.
MARKS
Dated signature of
arks Obtained Teacher
Process Product
Related(35) Related(15) Total(50)
mm
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
7
Name of Student Swati Padhi
Roll No. 20203C0038
Class CO5I-C
Experiment No 14
Title of Experiment Write a program to demonstrate the use of InetAddress class and its
factory methods.
Experiment-14
}
Output:
Ans
IP v4 IP v6
1. IPv4 protocol has address length of 1. On other hand IPv6 has 128-bit
32-bit represented in decimal format address length represented in
and it supports Manual and DHCP hexadecimal format and supports
configuration. Auto-configuration and
renumbering configuration.
2. IPv4 is being used as less 2. IPv6 has its inbuilt security
secure protocol as its security feature named as IPSEC (Internet
section is dependent on Protocol Security) which provide
application i.e., it is proportional additional security feature along
to the security that is provided or with the security provided or
implemented at application level. implemented at application
level.
Ans Step 1: Click Start Menu > Control Panel > Network and Sharing Center or
Network and Internet > Network and Sharing Center.
Step 2: Click Change adapter settings.
Step 8: Enter the IP address, Subnet mask, Default gateway, and DNS
server.
MARKS
Dated signature of
arks Obtained Teacher
Process Product
Related(35) Related(15) Total(50)
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
6
Name of Student Swati Padhi
Roll No. 20203C0038
Class CO5I-C
Experiment No 15
Title of Experiment Write a program to demonstrate the use of URL and URLConnection class
and its methods
Experiment-15 Exercise:
1. Write a program using URL class to retrieve the host,protocol,port and file of
URL http://www.msbte.org.in
Ans
}catch(Exception e){System.out.println(e);}
Output:
2. Write a program using URL and URLConnection class to retrieve the date,
content type, content length information of any entered URL.
Ans
import java.net.*;
{ int
a;
URL b = new
URL("https://www.esakal.com/");
URLConnection hpCon = b.openConnection();
long d = hpCon.getDate(); if(d==0)
}}
Output:
Marks
Dated signature of
Marks Obtained
Teacher
Process Product
Related(35) Related(15) Total(50)
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
`
6
Name of Student Swati Padhi
Roll No. 20203C0038
Class CO5I-C
Experiment No 18
Title of Experiment Write a program to demonstrate the use of URL and URLConnection class
and its methods
Experiment-18
Exercise
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/emp","root", "");
Statement s = con.createStatement();
ResultSet rs = s.getResultSet(); if
(rs != null) while ( rs.next() )
s.close(); con.close();
}
catch (Exception e)
{
System.out.println(e);
OUTPUT:
On Next page
1. Develop a program to display the name and roll_no of students from
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/marks","root","");
Statement s = con.createStatement();
s.execute("create table student ( stu_id varchar(10),stu_name varchar(20),marks
Integer(3))");
s.close(); con.close();
}
Output:
On next Page
`
Ans Class.forName() method returns the class object associated with the class
object associated with the class or interface passed as first parameter.
3. Write the steps to establish the DSN oriented connection and DSN Less
connection.
1. connect to a DSN
`
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
4.
Dated signature of
arks Obtained Teacher
Process Product
Related(35) Related(15) Total(50)
8
Name of Student Swati Padhi
Roll No. 20203C0038
Class CO5I-C
Experiment No 22
Title of Experiment Write a Servlet program to send username and password using HTML
forms and authenticate the user.
Experiment-22
Exercise
1. Develop servlet program to retrieve data from List and Radio Button using
HTML Forms. Ans
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
Welcome
<br>
<br>
<form action="Form">
Email : <input type="text" name="email"> <br>
<option name="Course">Javascript</option>
</select>
</form>
</body>
</html>
Form.java
javax.servlet.ServletException; import
import javax.servlet.http.HttpServletResponse;
@WebServlet("/MyForm") public
{
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
String em = request.getParameter("email");
String un = request.getParameter("uname");
String pa = request.getParameter("pass"); String
ge = request.getParameter("gender"); String co =
request.getParameter("Course");
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
Output:
2. Develop a program to receive student subject marks through HTML forms
TextField and send the response as passed or Failed in Examination.
Ans
Form.java
{
PrintWriter pw = res.getWriter(); res.setContentType("text/html");
String name = req.getParameter("name"); String
marks = req.getParameter("marks"); int m =
Integer.parseInt(marks); if(m>=80)
{ pw.println("Passed");
else{ pw.println("Failed");
doGet(req,res);
index.html
<!DOCTYPE html>
<html>
<body>
<form action="Form">
Enter the name:<input type ="text" name ="name">
Enter the marks:<input type ="text" name ="marks">
<input type="submit" value="Enter">
</select>
</form>
</body>
</html>
Output:
1. List the types of servlet and default port for there services.
Ans There are two main servlet types, generic and HTTP:
1) Generic servlets
2) HTTP servlets
b) Generic servlets have built-in HTTP protocol support and are more
useful in a Sun Java System Web Server environment.
Ans
GET(doGet()) POST(doPost())
ServletContext: ServletContext is
the object created by Servlet
Container to share initial parameters
or configuration information to the
whole application.
1. int readLine(byte[] b, int off, int len) it reads the input stream.
The ServletOutputStream class provides print() and println() methods that are
overloaded.
8. void println{}
Marks
Dated signature of
Marks Obtained Teacher
Process
Related(35) Product Related(15) Total(50)
Program: Computer Engineering (NBA Accredited)
Course - Advanced Java Programming (22515)
Practical Answer Sheet
`
12