Unit 5 Cwipedia If Fild
Unit 5 Cwipedia If Fild
e-Exam Manage Questions for Advanced Java Programming (17625) for topic 5 Go Back to Subjects
Q To Fig Q Mar
Question Answer Edit
No pic ure Type ks
2 ..................... is the first phase of the servlet life cycle. 5 N R 1 Initialization Edit
3 4.Name the class that includes the getSession() method 5 N R 1 HttpSession Edit
4 A cookie contains _____________ 5 N R 1 State information of user like name, address Edit
15 Advantage of JSP over Servlet is____________ 5 N R 1 JSP is web page scripting language and servlets are Java programs Edit
17 An object of Which is created by the web container at time of deploying 5 N R 1 ServletContext Edit
the project?
18 By default, how long does a cookie last? 5 N R 1 By default, a newly created cookie persists until the browser exits. Edit
22 CGI was expensive in terms of ___________and _________to create 5 N R 1 Process,Memory, Resource Edit
separate process for each client reqest
29 Different methods used by cookie class are 5 N R 1 All of the above Edit
30 During Initialization of Servlet, a servlet instance can throw ________. 5 N R 1 Both i) and ii) Edit
33 Following method is not valid life cycle method of JSP 5 N R 1 jspStop() Edit
39 Give the examples of Application Server from the following? 5 N R 1 All of the above Edit
How can we get context init parameter and run some code before rest
40 5 N R 1 ServletContextListener Edit
of the application can service a client?
43 How many copies of a JSP page can be in memory at a time? 5 N R 1 one Edit
48 Identify correct syntax of service() method of servlet class 5 N R 1 void service(ServletRequest req, ServletResponse res) Edit
49 If an expiration date is not explicitly assigred to a cookie __________ 5 N R 1 it is deleted when the current browser session ends Edit
If you want to track active session or how many users are there?
50 5 N R 1 HttpSessionListener Edit
which listener you should use.
In HTTP Request Which Asks for the loopback of the request message,
53 5 N R 1 TRACE Edit
for testing or troubleshooting?
59 In which phase of JSP life cycle ,JSP page turns into servlet? 5 N R 1 JSP Compilation Edit
Java servlets are an efficient and powerful solution for creating …………..
61 5 N R 1 Dynamic content Edit
for the web.
62 javax.servlet package does not contain following class or interface. 5 N R 1 HttpServlet Edit
72 JSP Start and end With the Symbol 5 N R 1 <% %> Edit
74 Life cycle of a JSP page consist of following steps. 5 N R 1 Translation,compilation,Loading and initialization,Request Handling,Destroy Edit
Name a class that includes the getSession() method that is used to get
76 5 N R 1 HttpServletRequest Edit
the HttpSession
Name the class that can be used to get the cookies from the client
77 5 N R 1 HttpServletRequest Edit
browser
78 Name the http method that sends the same response as the request. 5 N R 1 TRACE method Edit
79 Name the http method used to send resources to the server 5 N R 1 PUT method Edit
81 Name the location of compiled class files within a jar file? 5 N R 1 /WEB-INF/classes Edit
State true or false for the following statements in Java. i) Java beans
88 slow down software development process. ii) Java Servlets do not 5 N R 1 i-false, ii-false Edit
have built in multithreading feature.
90 The GET and POST methods are specified in _________. 5 N R 1 an HTML form Edit
The init parameter name and value pairs that are defined in web.xml
94 5 N R 1 ServletConfig Edit
file are handled by ______________ Object.
96 The javax.servlet.jsp package has two interfaces find in the following? 5 N R 1 JspPage & HttpJspPage Edit
99 The major difference between servlet and CGI is 5 N R 1 Servlets are thread based and CGI is process based Edit
100 The maximum size of data can be sent by doGet() of HTTP request is 5 N R 1 240 bytes Edit
104 The whole life cycle of a servlet breaks up into 3 phases: 5 N R 1 Initialization, Service , Destroy Edit
The _______ method is called when the servlet is first created, and is
105 5 N R 1 init Edit
not called again as long as the servlet is not destroyed.
This method is called once just before the servlet is unloaded and
108 5 N R 1 public void destroy() Edit
taken out of service.
111 To get the servlet environment information 5 N R 1 ServletContext object is used Edit
114 What are the correct statements about filter? 5 N R 1 All of these Edit
115 What are the true sentences about Session-Id? 5 N R 1 All of these Edit
118 What is invoked via HTTP on the Web server computer when it 5 N R 1 Java Servlet Edit
responds to requests from a user's Web browser?
120 What is servlet? 5 N R 1 Servlets are small program used for developing and executing web applications. Edit
123 What method is used to specify a container's layout in JSP? 5 N R 1 setLayout() Edit
What value does readLine() returns when it has reached the end of a
126 5 N R 1 Null Edit
file in JSP?
128 Where the session data will store ? 5 N R 1 Session objects. Edit
130 Which among the below is the class of javax.servlet package 5 N R 1 GenericServlet Edit
131 Which are true about tag libraries in web applications? 5 N R 1 all of the above Edit
Which cookie it is valid for single session only; it is removed each time
133 5 N R 1 Non-persistent cookie Edit
when user closes the browser?
Which HTTP method gets invoked when a user clicks on a link? Select
134 5 N R 1 GET method Edit
the one correct answer
Which http method send by browser that asks the server to get the
135 5 N R 1 get Edit
page only?
136 Which interface declares life cycle method of servet? 5 N R 1 Servlet Edit
139 Which is least visibility scope for Javabean in JSP 5 N R 1 Page Edit
140 Which is not the method in servlet to handle http request 5 N R 1 doShow() Edit
141 Which JSP tag is used to transfer processing to another JSP page ? 5 N R 1 <jsp:forward> Edit
142 Which life cycle method is used to process a client's request? 5 N R 1 service() Edit
143 Which method are central to life cycle of a servlet? 5 N R 1 init(), service() and destroy() Edit
144 Which method decides whether doGet() or doPost() method to call? 5 N R 1 service Edit
145 Which method does not exist on HttpServlet class? 5 N R 1 init() Edit
146
Which method is called on every servlet request ? 5 N R 1 service() Edit
Which method is used in the servlet class, to retrieve the input values
147 5 N R 1 request.getParameter() Edit
from HTML page?
148 Which method is used to end servlet lify cylce 5 N R 1 destroy Edit
149 Which method is used to extract cookies from a request? 5 N R 1 getCookies() Edit
Which method is used to specify before any lines that use the
150 5 N R 1 setContentType() Edit
PrintWriter?
Which method of the component class is used to set the position and
153 5 N R 1 setBounds() Edit
size of a component in JSP?
154 Which methods are available in ServleContext interface? 5 N R 1 getAttribute(),getMimeType(String File),void Log(String s) Edit
Which metod allows the client to send data of unlimited length to the
155 5 N R 1 doPost() Edit
web pageserver a single time.
156 which of following is not true for servlet? 5 N R 1 it is single threaded Edit
158 Which of the following are examples of JSP directive. 5 N R 1 include Edit
160 Which of the following are the session tracking techniques? 5 N R 1 URL rewriting, using session object, using cookies, using hidden fields Edit
Which of the following is legal JSP syntax to print the value of i. Select
164 5 N R 1 <%int i = 1;%> Edit
the one correct answer
Which of the following JSP variables are not available within a JSP
167 5 N R 1 httpsession Edit
expression. Select the one correct answer.
168 Which of the following method does not exist in HttpServelet class? 5 N R 1 init Edit
169 Which of the following method is used to destroy the session? 5 N R 1 destroy( ) Edit
176 Which packages represent interfaces and classes for servlet API? 5 N R 1 both a and b Edit
179 Which tag is used to declare one or more variables or methods 5 N R 1 <%!-----%> Edit
180 Why JSP is basically used today? 5 N R 1 b) To develop server pages Edit
181 _____ is the first phase of servlet lifer cycle 5 N R 1 initialization Edit
_____ Method returns true if the server created the session and it has
182 5 N R 1 isNew() Edit
not yet been accessed by the client.
186 ____________ is used to read data from a client request. 5 N R 1 ServletRequest Edit
192 …………………. Life cycle method handles all client request. 5 N R 1 service( ) Edit
Consider the following program and identify the missing method name
****** if you want to implement HTTP POST. import java.io.*; import
javax.servlet.*; import javax.servlet.http.*; public class
ColorGetServlet extends HttpServlet { public void ******
194 (HttpServletRequest request, HttpServletResponse response) throws 5 N A 2 doGet() Edit
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(); } }
197 _________ contains classes and interfaces required to build servlets 5 N U 2 javax.servlet Edit
<form action=”/handler”> <!-- form tags here --> </form> The URL
pattern /handler is mapped to an HTTP servlet. Which HttpServlet
service method will the web container call in response to this form
198 5 N A 2 doGet() Edit
submit? The URL pattern /handler is mapped to an HTTP servlet. Which
HttpServlet service method will the web container call in response to
this form submit? -->
204 1. Find out correct syntax of service() method of servlet class 5 N U 2 void service(ServletRequest req, ServletResponse res) Edit
205 1. Select correct scopes into JSP 5 N U 2 page, request, session, application Edit
A servlet life cycle can be defined as the entire process from its
217 creation till the destruction. The following are the paths followed by a 5 N A 2 All of above Edit
servlet
219 Advantage of Servlet over CGI is____________ 5 N U 2 Performance of servlets is significantly better. Edit
Among the given options choose the correct HTML file that will request
the below servlet: import java.io.*; import javax.servlet.*; import
javax.servlet.http.*; public class HelloForm extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException { <html> <body> <form action="HelloForm"
response.setContentType("text/html"); PrintWriter out = method="GET"> First Name: <input type="text"
222 response.getWriter(); String title = "Using GET Method to Read Form 5 N A 2 name="first_name"> <br /> Last Name: <input Edit
Data"; out.println("<html>\n" + "<head><title>" + title + "</title> type="text" name="last_name" /> <input
</head>\n" + "<body bgcolor=\"#f0f0f0\">\n" + "<h1 type="submit" value=&quo
align=\"center\">" + title + "</h1>\n" + "<ul>\n" + " <li><b>First
Name</b>: " + request.getParameter("first_name") + "\n" + " <li>
<b>Last Name</b>: " + request.getParameter("last_name") + "\n" + "
</ul>\n" + "</body></html>"); } }
An application wants to invalidate the sessions both programmatically httpRequest.getSession().invalidate() <session-config> <session-
223 5 N A 2 Edit
and declaratively. Select the best match to do this. timeout>someValueInMinutes</session-timeout> </session-config>
Analyse the following code and find out error. import java.io.*; import
javax.servlet.*; import javax.servlet.http.*; public class
AddCookieServlet extends HttpServlet { public void
doPost(HttpServletRequest request, HttpServletResponse response)
throwsServletException, IOException { String data =
225 5 N A 2 Error is in statement in which Cookie is added Edit
request.getParameter("data"); Cookie cookie = new
Cookie("MyCookie",data); response.addCookie();
response.setContentType("text/html"); PrintWriter pw =
response.getWriter(); pw.println("<B>MyCookie has been set to
"+data); pw.close(); } }
1. Open text editor type html program save it witn .html extension 2. Save .html
226 Arrange the steps in correct order to run JSP Program 5 N A 2 file in tomcat\webapps\ebanking 3. open text editor and type JSP program and Edit
store in same directory given above
Assume that you need to write a JSP page that adds numbers from
one to ten and then print the output. <% int sum=0; for(int
227 i=1;i<=10;i++) { %> <%sum=sum+i; %> <% } %> YYY Which 5 N A 2 <%=sum %> Edit
statement must be added at the location of YYY to print the sum of ten
numbers.
Assume that you need to write a JSP page that adds numbers from
one to ten, and then print the output. <% int sum = 0; for(j = 0; j <
228 10; j++) { %> // XXX --- Add j to sum <% } %> // YYY --- Display ths 5 N U 2 <% sum = sum + j; %> Edit
sum Which statement when placed at the location XXX can be used to
compute the sum. Select the one correct statement
231 Choose correct scopes into JSP:- 5 N U 2 page, request, session, application Edit
242 writer.println("Thank you, you are already logged in"); 5 N A 2 import javax.servlet.http.*; import java.io.*; import java.util.*; import Edit
writer.println("Here is the data in your session"); Enumeration names javax.servlet.*;
= session.getAttributeNames(); while (names.hasMoreElements()) {
String name = (String) names.nextElement(); Object value =
session.getAttribute(name); writer.println("<p>name=" + name + "
value=" + value + "</p>"); } } writer.println("<p><a
href=\"/ServletSession/login.html\">Return" + "</a> to login
page</p>"); writer.println("</body></html>"); writer.close(); } catch
(Exception e) { e.printStackTrace(); } } }
Choose missing statment for the following code public class Hello
extends HttpServlet { public void service(HttpServletRequest
request,HttpServletResponse response) throws
ServletException,IOException {
response.setContenetType("text/html"); printWriter
247 5 N A 2 import java.io.*; import javax.servlet.; import javax.servlet.http.*; Edit
out=response.getWriter(); BufferReader in=request.getReader();
out.println("<HTML>"); out.println("<HEAD><TITLE>Hello</TITLE>
</HEAD>"); out.println("<BODY>"); if
(request.getParameter("name")==null) out.println("Hello wordl");
out.println("</BODY></HTML>"); } }
Choose the correct code that displays the output as shown in the
figure
Figure:-
• Write the servlet source code. We need to import the javax.servlet package and
the javax.servlet.http package in your source file. • Compile your source code. •
253 Choose the correct sequence steps for running the servlet 5 N U 2 Edit
Create a deployment descriptor. • Run Tomcat. • Call your servlet from a web
browser.
254 Choose the correct syntax of directive 5 N A 2 <%@ directive_name %> Edit
Choose the missing statement in the given method syntax public void
256 doGet(HttpServletRequest request, HttpServletResponse response) 5 N A 2 IOException Edit
throws ____________
code JSP page to display the current date and time. Select the proper
statement from the following AT *____________line <Html> <Head>
<Title>JSP Expressions</Title> </Head> <Body> <H2>JSP
Expressions</H2> <ul> *__________________________ <li>Server:
258 5 N A 2 <li>Current time: <%= new java.util.Date() %> Edit
<%= application.getServerInfo() %> <li>Session Id: <%=
session.getId() %> <li>The <code>test param</code> form
parameter: <%= request.getParameter("testParam")%> </ul>
</Body> </Html>
Complete the code below to set the session object false at given
underlined line import java.io.*; import javax. Servlet.*; import
javax.servlet. Http.*; public class Example3 with Session extends
HttpServlet { public void do Get (HttpServletRequest
req,HittpServletResponse res ) throuws ServletException, IOException
{ String color = req. get Parameter("color"); // res. get
259 contentType("text"); PrintWriter pw = res. getWirter(); pw. printIn (" 5 N A 2 httpSession Session= req.getSession(false); Edit
<B> the Selected color = "); pw. printIn (color ) ; pw. print In ("<B>
Test the session <br>");
______________________________________________________ if
(session ==null { pw. printIn ("no session was available" ); pw. printIn
(making one ....."); session = reqq.getSession (); } else { pw. print In
(" there was a session " +session); } pw. close () ; } }
consider below program and print message " hi h r u" . select proper
method. import java.io.*; import javax.servlet.*; import
javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
private String message; public void init() throws ServletException { throws ServletException, IOException {
260 message = "hi h r u"; } public void doGet(HttpServletRequest request, 5 N A 2 response.setContentType("text/html"); PrintWriter out = Edit
HttpServletResponse response) throws ServletException, IOException response.getWriter(); out.println("<h1>&quo
{ response.setContentType("text/html"); PrintWriter out =
response.getWriter(); } public void destroy() { } }
Consider following code of servlet and find out missing method in the
consider the following four codes for index.jsp. Select any one option <html> <body> <%! int cube(int n){ return n*n*n*; } %> <%=
267 5 N A 2 Edit
which will print following output. Cube of 3 is: 27 "Cube of 3 is:"+cube(3) %> </body> </html>
Consider the following code and find which statement has error. <%@
taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <%@
taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html>
<head><title>Using the JSTL functions</title></head> <body>
<h2>Using JSTL functions</h2> <c:set var="string" value="Welcome!
to the site of roseindia.net"/> The length of the String:
268 ${fn:lengthOf(string)}<br> Does the String contain "Welcome"? 5 N A 2 Both A and B Edit
${fn:contains(string,"Welcome")} <br> Converting the String into
upper case using fn:toUpperCase(): ${fn:toUpperCase(string)}<br>
Converting the String into lower case using fn:toLowerCase():
${fn:toLowerCase(string)}<br> Making the substring of
"roseindia.net" : ${fn:substrings("roseindia.net", 0,9)} </body>
</html>
Consider the following code. Select the missing statement in the given
code. import java.io.*; import javax.servlet.http.*; public class
CookieExample extends HttpServlet { public void doGet(
HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException {
response.setContentType("text/html"); PrintWriter out =
response.getWriter(); // print out cookies Cookie[] cookies =
269 5 N A 2 missing package file Edit
request.getCookies(); for (int i = 0; i < cookies.length; i++) { Cookie c
out.println("</HTML>"); }
Consider the following program and identify the class at bank space
import java.io.*; import javax.servlet.*; import javax.servlet.http.*;
public class Ser extends __________________ { public void
277 doGet(HttpServletRequest rq,HttpServletResponse res) throws 5 N A 2 HttpServlet Edit
ServletException,IOException { res.setContentType("text/html");
PrintWriter out=res.getWriter(); out.println("<h1> hello </h1>");
out.println("hello"); out.close(); } }
Consider the following program and identify the missing method name
****** if you want to implement HTTP GET. import java.io.*; import
javax.servlet.*; import javax.servlet.http.*; public class
ColorGetServlet extends HttpServlet { public void ******
280 (HttpServletRequest request, HttpServletResponse response) throws 5 N A 2 doGet() Edit
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(); } }
Correct the following code. import java. Io. * ; import javax. Servlet. * ;
import javax. Servlet. Http.*; public class cookies Example extends
HttpServlet { public void dopost ( HttpServletRequest
req,HttpServletResponse res ) throws ServletException, IOException {
res. set content type ( "text/html"); String dta = req. get Parameter
("data"); PrintWriter pw = res. getWriter (); cookie cookie = new
Cookie ( "My cookies " data) ; cookie.setMaxAge(1); req.addCookie
Debug the following code and find which statement contains error.
import java.io.*; import javax.servlet.*; import javax.servlet.http.*;
public class DemoServlet extends HttpServlet { public void
306 service(HttpServletRequest req,HttpServletResponse res) throws 5 N A 2 No error Edit
ServletException,IOException { res.setContentType("text/html");
PrintWriter pw= res.getWriter(); pw.println("<h2> Welcome to servlet
programming..."); pw.close(); } }
311 During initialization of servlet a servlet instance can throw 5 N U 2 Both Edit
Find correct output of following code HTML FILE <html> <body> <form
action=”pass1”> name:<input type=”text” name=”t1”> password:
<input type = “password” name=”t2”> <input type=”submit”
value=”login”> </form> </body> </html> // Servlet file import
java.io.*; import javax.servlet.*; public class pass1 extends
GenericServlet { public void service(ServletRequest Firstly input username & password then it displays "welcome to home
315 5 N A 2 Edit
req,ServletResponse res)throws ServletException, IOException { page"
res.setContentType(“text/html”); PrintWriter pw = res.getWriter();
String un=”abc”; String pwd=”xyz”; String p1=req.getParameter(“t1”);
String p2=req.getParameter(“t2”); if((p1.equals(un)) &&
(p2.equals(pwd))) { pw.println(“<h1>welcome to home page</h>”);
}else{ pw.println(“invalid”); } pw.close(); } }
Find error in following code from given options. import java.io.*; import
javax.servlet.*; import javax.servlet.http.*; public class
ColorPostServlet extends HttpServlet { public void
doPost(ServletRequest request,ServletResponse response)throws
316 5 N A 2 Error in doPost() method Edit
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(); } }
Find out the error in the following code. import java.io.*; import
javax.servlet.*; public class servlet extends HTTPServlet { public void
service(ServletRequest request, ServletResponse response) throws
319 ServletException, IOException { 5 N A 2 Mismatch servlet Edit
response.setContentType("text/html"); PrintWriter printwriter =
response.getWriter(); printwriter.println("<B>Hello from Java!</B>");
printwriter.close(); } }
null; // Get an array of Cookies associated with this domain if( cookies
320 != null ){ out.println("<h2> Found Cookies Name and Value</h2>"); 5 N A 2 cookies = request.getCookies(); Edit
for (int i = 0; i < cookies.length; i++){ cookie = cookies[i];
out.print("Name : " + cookie.getName( ) + ", "); out.print("Value: " +
cookie.getValue( )+" <br/>"); } }else{ out.println("<h2>No cookies
founds</h2>"); } %> </body> </html>
Find out the missing statement to get the correct output in bellow
program import java.io.*; import javax.servlet.*; import
javax.servlet.http.*; import java.util.*; public class SessionTracking
extends HttpServlet { public void doGet(HttpServletRequest
req,HttpServletResponse res)throws ServletException,IOException {
res.setContentType("text/html"); PrintWriter w=res.getWriter();
Integer count=(Integer)ss.getAttribute("tracker.count");
322 if(count==null) { count=new Integer(1); } else count=new 5 N A 2 HttpSession ss=req.getSession(); Edit
Integer(count.intValue()+1); ss.setAttribute("tracker.count",count);
w.println("<h1>Sessiontracking Demo</h1>"); w.println("You have
visited this page"+count+"times"); w.println("here is session data");
Enumeration enu=ss.getAttributeNames();
while(enu.hasMoreElements()) { String name=
(String)enu.nextElement(); w.println(name+"
"+ss.getAttribute(name)); } } }
Find the statement missing in the below code import java.io.*; import
javax.servlet.*; public class HelloWorld extends HttpServlet { public
324 void doGet(HttpServletRequest request, HttpServletResponse 5 N U 2 both A and B Edit
response) throws ServletException, IOException { PrintWriter out =
response out.println("Hello World"); } }
following is the code to get all the cookies . choose the proper option
to fill the blank space in the code Cookie ck[]=request.getCookies();
327 for(int i=0;i<ck.length;i++){ out.print("<br>"+ck[i].getName()+" 5 N A 2 ck[i].getValue()); Edit
"+_____________________________//printing name and value of
cookie }
330 Following statement means: HttpSession getSession( ) 5 N U 2 It will return existing session object,If not it will create a new sesssion. Edit
332 For a HttpSession, say session, how do you get its attribute? 5 N U 2 session.getAttribute("lastName") Edit
For the below html code: <input type="text" name="username”> The String str=req.getParameter("username"); where req is
335 5 N U 2 Edit
servlet code to retrieve the value from the text box is: HttpServletRequest object
For the following code identify the correct syntax of service () method
of servlet class. import java.io.*; import javax.servlet.*; public class
HelloServlet extends GenericServlet { public void
336 5 N A 2 void service(ServletRequest req,ServletResponse res) Edit
service(___________________)throws ServletException, IOException
{ response.setContentType("text/html"); PrintWriter pw =
response.getWriter(); pw.println("<B>Hello"); pw.close(); } }
For the following code select the missing statement that can be used .
import java.io.*; import java.net.*; import javax.servlet.*; public class
Exp extends GenericServlet{ public void service(ServletRequest
337 request, ServletResponse response) throws ServletException, 5 N A 2 String name=request.getParameter("name"); Edit
IOException { response.setContentType("text/html"); PrintWriter out =
response.getWriter(); out.println("<b>Values u entered are:</b>");
out.println("Hello "+name+"<br>"); out.close(); } }
For the following output, what is the html <form> tag code?
Figure:-
339 Generic servlet implements the _________&_______ interface. 5 N U 2 Servlet & servlet config Edit
341 getSession(true) method will return appropriate session object if…… 5 N U 2 the session is existing Edit
Given the following servlet mapping definition for the web application
named 'secureapp', <servlet> <servlet-
name>ProcessLoginData</servlet-name> <servlet-
347 class>DoLogin</servlet-class> </servlet> <servlet-mapping> <servlet- 5 N U 2 http://localhost:8080/secureapp/do/Login?name="bob" Edit
name>ProcessLoginData</servlet-name> <url-pattern>do/Login</url-
pattern> </servlet-mapping> which of the following URLs will correctly
request the Servlet?
Given: <%-- insert code here --%> <html> <body> Today is: <%= new
348 5 N A 2 <%@ page import='java.util.Date' %> Edit
Date() %> </body> </html> What needs to go on line 1?
350 How does Tomcat execute a JSP? 5 N U 2 By one of Tomcat's threads Edit
How is the form data stored as a cookie on client machine? Pick out the
correct servlet code for the below html code: <html> <head> <meta
http-equiv="Content-Type" content="text/html; charset=UTF-8"> String s=request.getParameter("myname"); Cookie c=new
351 5 N A 2 Edit
<title>Form</title> </head> <body> <form method="get" Cookie("name", s); response.addCookie(c);
action="CServlet"> Enter your name : <input type="text"
name="myname"> <input type="submit" value="go"> </form>
</body> </html>
355 Identify correct syntax of addCookie() method 5 N U 2 void addCookie(Cookie cookie) Edit
356 Identify correct syntax of doPost() method used in servlets. 5 N U 2 void doPost(HttpServletRequest req,HttpServletResponse res) Edit
357 Identify correct syntax of service() method of servlet class 5 N U 2 void service(ServletRequest req, ServletResponse res) Edit
360 Identify the correct sequence in Lifecycle of JSP 5 N U 2 Compile, Initialize, Execute, Destroy Edit
If your servlet class file does not have a package statement, the
364 5 N A 2 TomcatRootDir\webapps\examples\WEB-INF\classes Edit
servlet .class file must be placed in ________ by default.
In a URL query string, the parameter name and value are associated
366 5 N U 2 = Edit
using the ____ symbol.
In following Java program fill statement showing *** . Select any one
option from given options import java.io.*; import java.util.*; import
javax.servlet.*; import javax.servlet.http.*; public class DateServlet
extends HttpServlet{ public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{
368 HttpSession hs = ***************** 5 N A 2 request.getSession(true); Edit
response.setContentType(“text/html”); PrintWriter
pw=response.getWriter(); pw.print(“<B>”); Date date=
(Date)hs.getAttribute(“date”); if(date!=null){ pw.print(“Last
access:”+date+”<br>”); } date =new Date(); hs.setAttribute(“date”,
date); pw.println(“Current date:”+date); } }
In HTTP Request Which Asks for the loopback of the request message,
384 5 N A 2 TRACE Edit
for testing or troubleshooting?
386 In JSP Action tags which tags are used for bean development? 5 N U 2 All mentioned above Edit
388 In order to run JSP .................... is required. 5 N U 2 Java Web Server Edit
393 In the following statements identify the disadvantages of CGI? 5 N U 2 All mentioned above Edit
397 In which folder we have to save java file for servlet? 5 N U 2 classes Edit
409 JSP includes a mechanism for defining --------------- or custom tags. 5 N U 2 dynamic attributes Edit
411 JSP tags are divided into which types? 5 N U 2 All the above Edit
412 methods that set the cookie attributes are : ____________________ 5 N U 2 A & B Both Edit
n the following code, what are the statements within doGet() method
to display "Hello from Servlet" on the web browser. import
java.io.IOException; import java.io.PrintWriter; import
javax.servlet.ServletException; import javax.servlet.http.HttpServlet;
415 import javax.servlet.http.HttpServletRequest; import 5 N A 2 PrintWriter pr=response.getWriter(); pr.println("Hello from Servlet"); Edit
javax.servlet.http.HttpServletResponse; public class NewServlet
extends HttpServlet { protected void doGet(HttpServletRequest
request, HttpServletResponse response) throws ServletException,
IOException { } }
Name the class that can be used to get cookies from the client
416 5 N U 2 HttpServletRequest Edit
browser.
Of the following four valid comment styles that can be used within JSP
419 5 N A 2 <!-- (c)2000 mabte.com --> Edit
pages, which can the end user see?
426 Select advantage of JSP from the following - 5 N U 2 All of the mentioned Edit
427 Select appropriate syntax for adding cookie. 5 N U 2 HttpServletResponse-object.addCookie(Cookie obj); Edit
Select the correct statement to get the output import java.io.*; import
Select the missing method from following code. public class HelloForm
extends HttpServlet { public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{ Cookie firstName = new
Cookie("first_name",request.getParameter("first_name")); Cookie
Name = new Cookie("last_name",
request.getParameter("last_name"));
firstName.setMaxAge(60*60*24); lastName.setMaxAge(60*60*24);
433 5 N A 2 response.addCookie( Name ); Edit
response.addCookie( firstName );
response.setContentType("text/html"); PrintWriter out =
response.getWriter(); String title = "Setting Cookies Example";
out.println( "<head><title>" + title + "</title></head>"+ "<h1
align=\"center\">" + title + "</h1>\n"+ " <li><b>First Name</b>: " +
request.getParameter("first_name") + "\n" + " <li><b>Last
Name</b>: " + request.getParameter("last_name") + "\n" + "\n" + "
</body></html>"); } }
Select the package used to import the abstract class HttpServlet and
436 5 N U 2 import javax.servlet.http.* Edit
interfaces HttpServletRequest and HttpServletResponse
Select the valid program which shows all life cycle methods of GenericServlet { public void init() { // initialization goes here } public void
439 5 N A 2 service(ServletRequest req,ServletResponse res) throws Edit
GenericServlet.
IOException,ServletException { // actual service is provided here } public void
destroy(){ }
440 Seperation of business logic from JSP this is the advantage of? 5 N A 2 Custom Tags in JSP Edit
441 service mthod of servelet is use 5 N U 2 to send request and to get response Edit
443 Servlet offer following advantage over CGI 5 N U 2 CGI is not platform independent but servlet are platform independent Edit
447 Servlets play important role in MVC Architecture as ------------- 5 N A 2 Controller Edit
State true or false for the following statements in Java i) Java beans
448 slow down software development process. Ii) Java servlets do not 5 N U 2 i-false,ii-false Edit
have built in multithreading feature.
449 Steps in JSP Page execution 5 N U 2 1. Compilation 2. Initialization 3. Execution 4. Cleanup Edit
Suppose the servlet class named Test does not have the package
450 5 N A 2 http://localhost:8080/examples/servlet/Test Edit
statement, by default, you use ________ to invoke it
Suppose you want to know each time request comes in, so that you
453 5 N U 2 ServletRequestListener Edit
can log it. Which listener is appropriate for that?
457 The correct sequence of JSP life Cycle is 5 N U 2 init(), Service(), destroy() Edit
458 The difference between servelets and JSP is the 5 N U 2 Syntax Edit
The doGet() method extract values of the parameters type and number
459 5 N U 2 request.getParameter() Edit
by using_____.
461 The following methods belongs to the life cycle methods of the servlet. 5 N U 2 All Of Above Edit
The following program contains two errors. Identify them from the
following- import java.io.*; import javax.servlet.*; import
javax.servlet.http.*; public class SessionDemo extends GenericServlet
{ public void doGet(HttpServletRequest request, HttpServletResponse
error 1: extends GenericServlet instead of HttpServlet error 2:
462 response) throws ServletException, IOException { 5 N A 2 Edit
response.getSession() instead of request.getSession()
response.setContentType("text/html"); PrintWriter out =
response.getWriter(); String n=request.getParameter("userName");
out.print("Welcome "+n); HttpSession session=response.getSession();
session.setAttribute("uname",n); out.close(); } }
464 The getAttribute(String attr) returns 5 N U 2 Returns value of the server attribute Edit
469 The include() method of RequestDispatcher ______. 5 N A 2 sends a request to another resource like servlet, jsp or html Edit
The init parameter name and value pairs that are defined in web.xml
470 5 N A 2 ServletConfig object Edit
are handled by.
472 The life cycle of a servlet is managed by______________- 5 N U 2 servlet container Edit
Generic servlet is protocol platform independent & HTTP servlet having built
473 The main difference between Generic Servlet and HTTP servlet is 5 N U 2 Edit
in HTTP protocol support
474 The major difference between servlet and CGI is 5 N A 2 Servlets are thread based and CGI is process based Edit
The service phase of the servlet life cycle represents all interactions
476 5 N U 2 destroyed Edit
with requests until the servlet is ......................
478 The Status code _____ shows “Resource Temporarily Moved” 5 N U 2 302 Edit
479 The values of <servlet-name> and <servlet-class> in web.xml file …… 5 N A 2 may be same Edit
The ________ directive lets you provide information for the page, such
480 as importing classes and setting up content type. The page directive 5 N A 2 page Edit
can appear anywhere in the JSP file.
483 Through which tag you can define servlet config in web.xml? 5 N U 2 init-param Edit
484 To declare the variables in JSP which tag is used 5 N U 2 Declaration Tag Edit
485 To get the servlet environment information. 5 N U 2 ServletConfig object is used. Edit
487 What are the methods available in ServletContextListener interface? 5 N U 2 contextInitialized((),contextDestroyed() Edit
488 What are the true sentences about Session-Id? 5 N A 2 All of these. Edit
What gets printed when the following is compiled. Select the one
correct answer. <% int y = 0; %> <% int z = 0; %> <% for(int
491 5 N A 2 3 Edit
x=0;x<3;x++) { %> <% z++;++y;%> <% }%> <% if(z<y) {%> <%=
z%> <% } else {%> <%= z - 1%> <% }%>
</HTML></BODY>"); out.close(); } }
496
What is default value of session attribute in JSP 5 N U 2 <%@ page session="true" %> Edit
response.setContentType("text/html"); PrintWriter pw =
response.getWriter(); pw.println("<B>Hello!"); pw.close(); } }
503 What is the difference between cookies and Httpsession? 5 N U 2 Cookies works at clientside whereas HttpSession works at serverside. Edit
504 What is the difference between GenericServlet and HttpServlet? 5 N U 2 all of the above Edit
What is the limit of the datato be passed from HTML when doGet() is
506 5 N U 2 2kb Edit
used?
513 What the getSession() method with true parameter will returned? 5 N U 2 the session is existing Edit
514 What the ServletContainer does? 5 N U 2 Provides the Runtime environment for servlets. Edit
what will be the final output after Enter the valute for First & Second
and also click on Clac Button? import javax.servlet.*; import
javax.servlet.http.*; import java.io.PrintWriter; import
java.io.IOException; public class calcServlet extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse
res)throws ServletException,IOException { PrintWriter
pw=res.getWriter(); res.setContentType("text/html"); pw.println("
<html><head><title>CALCULATOR</title></head>"); pw.println("
<body>"); pw.println("<form method=post action=calcServlet>");
pw.println("Enter first No.:"); pw.println("<input type=text name=nm>
<br>"); pw.println("Enter Second No.:"); pw.println("<input type=text
name=r>"); pw.println("<input type=submit value=calc>"); pw.println("
</form></body></html>"); pw.close(); } public void
doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException { String a=req.getParameter("nm");
String b=req.getParameter("r"); int c=Integer.parseInt(a); int
d=Integer.parseInt(b); int e=c+d; int f=c-d; int g=c*d; PrintWriter
pw=res.getWriter(); res.setContentType("text/html"); pw.println("
<html><head><title>CALCULATOR</title></head>"); pw.println("
<body>"); pw.println(a+"+"+b+"="+e+"<br>"); pw.println(a+"-
520 "+b+"="+f+"<br>"); pw.println(a+"*"+b+"="+g+"<br>"); int h=c/d; 5 Y3 U 2 o1 Edit
pw.println(a+"/"+b+"="+b+"<br>"); pw.println("</body></html>");
pw.close(); } public void destroy() {} }
Figure:-
What will be the output of the following code snippet? <% int a=5; %>
525 5 N A 2 a = 15 :: 10 Edit
<%! int a=10; %> a = <%=a + this.a%> :: <%= this.a%>
528 When using HTML forms which of the folowing is true for POST method 5 N U 2 POST method sends data in the body of the request Edit
529 Which Action element Includes file at time the page is requested in JSP. 5 N A 2 jsp:include Edit
530 Which among the below is not a method of Servlet Interface 5 N U 2 All are methods above are of Servlet Interface Edit
531 Which are the methods of servlet life cycle? 5 N A 2 b)init(),service(),destroy() Edit
Which are useful methods which you can use while manipulating
532 5 N A 2 All of above Edit
cookies in servlet?
Which class provides stream to read binary data such as image etc.
534 5 N U 2 ServltInputStream Edit
from the request object?
535 Which classes are present in javax.servlet.http package? 5 N U 2 HttpServlet Cookie Edit
538 Which cookie it is valid for single session only; it is removed each time 5 N U 2 Non-persistent Edit
when user closes the browser?
542 Which is least visibility scope for java beans In JSP 5 N U 2 Page Edit
544 Which is the Microsoft solution for providing dynamic Web content? 5 N A 2 ASP Edit
546 Which JDBC driver types can be used in either applet or servlet code 5 N U 2 type 3 and 4 Edit
547 Which JSTL code snippet can be used to perform URL rewriting? 5 N A 2 <a href='<c:url value="foo.jsp"/>' /> Edit
548 Which mechanism is included by jsp for defining custom tags? 5 N U 2 dynamic attributes Edit
552 Which method of the servlet is/are called several times in its life? 5 N U 2 doPost() Edit
Which methods are used to Extract all names or value pairs from the
556 5 N U 2 getParameterNames() and getParameterValues() Edit
Http request
559 Which of the following are examples of JSP directive. 5 N U 2 include Edit
560 Which of the following are the session tracking techniques? 5 N A 2 URL rewriting,using session object,using cookies,using hidden fields Edit
564 Which of the following is correct syntax of init() method of servlet ? 5 N U 2 void init(ServletConfig sc) throws ServletException Edit
Which of the following is legal JSP syntax to print the value of i Select
565 5 N U 2 <%int i = 1;%> <%= i %> Edit
the one correct answer
567 Which of the following is not true for servlet? 5 N U 2 It is single threaded Edit
570 Which of the following is true regarding TLD 5 N A 2 All of these Edit
Which of the following JSP variables are not available within a JSP
572 5 N U 2 httpsession Edit
expression. Select the one correct answer.
574 Which of the following methods are main methods in life cycle of servlet 5 N U 2 Service() Edit
576 Which of these statements are false about GenericServlet? 5 N U 2 Genric Servlet extends HttpServlet and override doGet() method Edit
588 Which tag is used to execute java source code in JSP 5 N U 2 Scriptlet Tag Edit
590 With JSP tag is used to transfer for processing another JSP page 5 N U 2 <jsp:use:include> Edit
Write the comments on following statements: 1 1.Sets the content type 2.PrintWriter object that you can use to send character
592 5 N A 2 Edit
res.setContentType(“text/html”); 2 PrintWriter pw = res.getWriter(); text to the client.
Write the method in the following code for adding cookies. import
java.io.*; import javax.servlet.*; import javax.servlet.http.*; public
class AddCookieServlet extends HttpServlet { public void
doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException { String data =
593 5 N A 2 addCookie Edit
You are creating a servlet that generates stock market graphs. You
want to provide the web browser with precise information about the
594 5 N A 2 response.setContentLength(numberOfBytes); Edit
amount of data being sent in the response stream. Which
HttpServletResponse methods will you use to provide this information?
Your web page includes a Java SE v1.5 applet with the following
declaration: <object classid='clsid:CAFEEFAC-0015-0000-0000-
595 ABCDEFFEDCBA' width='200' height='200'> <param name='code' 5 N U 2 Get Edit
value='Applet.class' /> </object> Which HTTP method is used to
retrieve the applet code?
602 Apache Tomcat is a ________. 5 N U 2 Web server that is capable of running Java programs. Edit