Sessional Paper 2
Sessional Paper 2
Q5.What is servlet? 1M
A. Servlets are small program used for developing and executing web applications.
B. Servlets are small program used for database applications
C. Servlets are used for intranet programming
D. Servlets are programs written in C and C++
1 www.gunwantmankar.com
Q.7 Select the proper method to retrieve the host name of local machine. 2M
A. a-b-c-d-e
B. d-a-e-b-c
C. e-d-c-b-a
D. d-a-c-b-e
Q11. Consider the following program what will be displayed in the output? 2M
import java.net.*;
class myAddress
{
public static void main (String args[])
{
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
}
catch (UnknownHostException e)
{
System.out.println("Could not find this computer's address.");
}
}
}
2 www.gunwantmankar.com
A. The internet address of the server
B. The internet address of the client
C. The internet address of the host
D. The internet address of any other PC
Q12. Choose the correct option to establish a connection to database named student
and display its contents. 2M
A.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
B.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
C.
import java.sql.*;
class Ddemo1
{
3 www.gunwantmankar.com
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
D.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(1)+" \t \t"+rs.getDouble(1));
}
s.close();
c.close();
}
}
import java.sql.*;
public class db15
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN","","");
PreparedStatement s=c.prepareStatement( "update db3 set Name=? where Roll_no=?");
Statement s=c.createStatement( );
s.setString(1,*);
s.setString(2,*);
s.setString(3,*);
s.executeUpdate();
4 www.gunwantmankar.com
ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
<html>
<body>
<center>
<form name="Form1"
action="http://localhost:8080/servlets-examples/ColorGetServlet">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>
Contents Of ColorGetServlet.java File :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
5 www.gunwantmankar.com
public class ColorGetServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>The selected color is: ");
pw.println(color);
pw.close();
}
}
Output of above program is
Opening : ColorGet.html File
16. A JSP page called test.jsp is passed a parameter name in the URL
using http://localhost/test.jsp?name="John". The test.jsp contains the
following code.
6 www.gunwantmankar.com
<%! String myName=request.getParameter();%>
<% String test= "welcome" + myName; %>
<%= test%>
A. The program prints "Welcome John"
B. The program gives a syntax error because of the statement
<%! String myName=request.getParameter();%>
C. The program gives a syntax error because of the statement
<% String test= "welcome" + myName; %>
D. The program gives a syntax error because of the statement
<%= test%>
1. Answer : B: getPort()
2. Answer: B: File path
3. Answer: C: Structured Query Language
4. Answer :D: Parametrized
5. Answer: A : Servlets are small program used for developing and executing web
applications.
6. Answer: C: InetAddress
7. Answer: A static InetAddressgetLocalHost( )throws UnknownHostException
8. Answer: D: All of above
9. Answer : B: d-a-e-b-c
10. Answer: C: Browser will interpret content as HTML source code.
11. Answer: C: The internet address of the host
12. Answer: A
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
13. Answer: A: Command line argument
14. Answer: C: public static Connection getConnection(String url, String name, String
password) throws SQLException
15. Answer: A: Output shown is correct
16. Answer:B:The program gives a syntax error because of the statement
<%! String myName=request.getParameter();%>
7 www.gunwantmankar.com