; CS506 Final Term 2012 Very important Guess
Learning Center
Plans & pricing Sign in
Sign Out

CS506 Final Term 2012 Very important Guess


CS506 Final Term 2012 Very important Guess

More Info
  • pg 1
									There are six JSP Actions:

Identify the advantages of JSP over Servlet.
a) Embedding of Java code in HTML pages
b) Platform independence
c) Creation of database-driven Web applications
d) Server-side programming capabilities

What is JSP Output Comments?
Answer: JSP Output Comments are the comments that can be viewed in the HTML source file.
       <!-- This file displays the user login screen -->
       <!-- This page was loaded on
       <%= (new java.util.Date()).toLocaleString() %> -->

Question: What is expression in JSP?
Expression tag is used to insert Java values directly into the output. Syntax for the Expression tag is:
        <%= expression %>
An expression tag contains a scripting language expression that is evaluated, converted to a String, and inserted
where the expression appears in the JSP file. The following expression tag displays time on the output:
        <%=new java.util.Date()%>

Question: What types of comments are available in the JSP?
Answer: There are two types of comments are allowed in the JSP. These are hidden and output comments. A
hidden comments does not appear in the generated output in the html, while output comments appear in the
generated output.

Example of hidden comment:
      <%-- This is hidden comment --%>
Example of output comment:
      <!-- This is output comment -->

Question: What is JSP declaration?
Answer: JSP Decleratives are the JSP tag used to declare variables. Declaratives are enclosed in the
<%! %> tag
and ends in semi-colon.

You declare variables and functions in the declaration tag and can use anywhere in the JSP. Here is the example
of declaratives:
<%@page contentType="text/html" %>
int cnt=0;
private int getCount(){
//increment cnt and return the value
return cnt;
<p>Values of Cnt are:</p>

Question: What is JSP Scriptlet?
Answer: JSP Scriptlet is jsp tag which is used to enclose java code in the JSP pages. Scriptlets begins with <%
tag and ends with %> tag. Java code written inside scriptlet executes every time the JSP is invoked.
 //java codes
  String userName=null;

Q.how do we define uses error pages in JSP?
There are two attributes in JSP directive
         < @page errorPage= /WEB-INF/error.jsp >
Specifies a JSP page that should process any Exceptions thrown but not caught in the current page.
This Attribute is only related for page-specific error pages only.
         < @page isErrorPage= true >
Indicates whether or not the current page can act as the error page for another JSP page.

Q.what is the difference b/w system.out.println() and out.println()
In Jsp i f we want to write some thing to response object we need to use out.println("some value");

in java if you want to write some thing to the console then we will write in
System.out.println("Some thing")
System.out is a stream to the console, not the response. This output will appear in the console window or log file

Q.what type of problem persist with structs framework

Q.in which situation expresion language can be used

Q.how can v lead cookies from the client

Q.how do v use JSP action element and what are there format
JSP Action Elements
JSP action elements allow us to work with JavaBeans, to include pages at request time and to forward
requests to other resources etc.

Expressed using XML syntax
-Opening tag <jsp:actionElement attribute=‖value‖ ….. >
-Body body
-Closing tag </jsp:actionElement>

Empty tags (without body) can also be used like
<jsp:actionElement attribute=‖value‖ ….. >

Q.why session tracking is important

30 mark of objective

Page directive 5marks

4tag liraries 5 marks

implicit object 2 marks
Implicit Objects
  To simplify code in JSP expressions and scriptlets, you are supplied with eight automatically defined variables,
  sometimes called implicit objects. The three most important variables are request, response & out. Details of
  these are given below:

     – request
        This variable is of type HttpServletRequest, associated with the request. It gives you access to the
        request parameters, the request type (e.g. GET or POST), and the incoming HTTP request headers
        (e.g. cookies etc).

     – response
        This variable is of type HttpServletResponse, associated with the response to client. By using it, you
        can set HTTP status codes, content type and response headers etc.

      This is the object of JspWriterused to send output to the client.

transient varible 2marks

whst is jsp scriplet 3 marks

what is expression language 3 marks

what is c:remove in jstl 2 marks
 As its name suggests, the c:remove action is used to delete a scoped variable, and takes two attributes. The var
attribute names the variable to be removed, and the optional scope attribute indicates the scope from which it
should be removed and defaults to page.

For example, to remove a variable named square from page scope, we’ll write:
      <c:remove var = ―square‖ />

And if variable email is required to be removed from request scope, then c:remove tag will look like:
       <c:remove var = ―email‖ scope = ―request‖ />

Discuss the MVC model 2 architecture (10marks)

Write the any two types of servelt (2marks)

What is used to join the thread (1marks)

Discuss the JSP Framework (10 marks)
       The JSP Framework
            —      Use regular HTML for most of the pages
            —      Mark servlet code with special tags
            —      Entire JSP page gets translated into a servlet (once), and servlet is what actually gets
                   invoked (for each request)
            —      The Java Server Pages technology combine with Java code and HTML tags in the same
                   document to produce a JSP file.

Advantages of JSP over php
      Versus PHP
                 —      JSPs offer better language for dynamic part
                 —      JSPs offer better tool support

How many types of JSP Comments are (2 marks)

Write the 3 types of JSP Action elements for - (3marks)

What is a package and how to create the package? Explain with an example (5marks)

What is the difference between custom tags and javabeans? (3 marks)

How cookies are sent to a client? (5marks)

MCQ teh
WDSL stands for
UDDI stands for
MVC stands for
From the following; which component is/are used in directory Structure of web components:
_ index.htm, JSP, Images etc..
_ Web-inf, web.xml
_ lib, jar files
_ All of these
From the following which one is not a built-in validator?
_ DoubleRangeValidator
_ LongRangeValidator
_ LengthValidator
_ StringValidator

___________ represent the state of component.
_ View
_ Model
_ Controller
_ Component

When defining a method you must include a ___________ to declare any exception that might be thrown but is
not caught in the method.
_ try block_ finally block_ catch block_ throws-clause

Converting bigger data types into smaller one is called ----------

Java provide ------------------
_ Overloading
_ Overriding
_ Pointers
_ Multiple Inheritance

5 Marks Quesstions
1. What are packages? and how they are organized?

a set of Java classes organized for convenience in the same directory to avoid the name collisions.
Packages are nothing more than the way we organize files into different directories according to their
functionality, usability as well as category they should belong to. An obvious example of packaging is the JDK
package from SUN (java.xxx.yyy

Basically, files in one directory (or package) would have different functionality from those of another directory.For
example, files in java.io package do something related to I/O, but files in java.net package give us the way to deal
with the Network.

The benefits of using package reflect the ease of maintenance, organization, and increase collaboration among

2. what are output comments in JSP?

Jsp comments are converted by the jsp engine into java comments in the source code of the servlet that
implements the Jsp page. The jsp comment don't appear in the output produced by the jsp page when it runs.
Jsp comments do not increase the size of the file, jsp page are useful to increase the readability of the jsp page.

A comment that is sent to the client in the viewable page source.The JSP engine handles an output comment as
uninterpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment
by viewing the page source from your Web browser.

JSP Syntax
<!-- comment [ <%= expression %> ] -->

Example 1
<!-- This is a comment sent to client on
<%= (new java.util.Date()).toLocaleString() %>

Displays in the page source:
<!-- This is a comment sent to client on January 24, 2004 -->

In Jsp two types of comments are allowed in the Jsp page:
1) Hidden comment: This comment will not appear in the output.
         <%-- Hidden comment --%>
2) Output comment: This type of comment will appear in the output.
         <!-- Output comment>
If we have to pass the comment inside the directive then there we use a single line comment i.e. //

3. Write Five operators used in Expression Language

3 Marks Questions

1. When tread's run() method is invoked?

After a thread is started, via its start() method or that of the Thread class, the JVMinvokes the thread's
run() method when the thread is initially executed.

2. which listener interfaces are used to handle mouse events?
To handle Mouse events, two types of listener interfaces are available.
   – MouseMotionListener
   – MouseListener
The class that wants to handle mouse event needs to implement                 the corresponding interface
and needs to provide the definition of all the methods in that interface.

        MouseMotionListener interface
    –   Used for processing mouse motion events
    –   Mouse motion event is generated when mouse is moved or dragged

       MouseListener interface
       – Used for processing “interesting” mouse events like when mouse is:
       ƒ Pressed
       ƒ Released
       ƒ Clicked (pressed & released without moving the cursor)
       ƒ Enter (mouse cursor enters the bounds of component)
       ƒ Exit (mouse cursor leaves the bounds of component)

3. why client side validation is used?

There are two good reasons to use client-side validation:
ƒ It's a fast form of validation: if something's wrong, the alarm is triggered upon
submission of the form.
ƒ You can safely display only one error at a time and focus on the wrong field, to
help ensure that the user correctly fills in all the details you need.

4. Write three types of custom tags
Three types of can be constructed. These are:
       1 Simple Tag
       2 Tag with Attribute
       3 Tag wit

1. Simple Tag
A simple tag has the following characteristics:
-Start and End of tag -No body is specified within tag -No attributes -For example

2.Tag with Attributes
   A tag with attributes has the following characteristics:
      -Start and End of tag
      -Attributes within tag
      -No body enclosed
      -For example
              < mytag:hello attribute = “value” />

3. Tag with Body
    A tag with body has the following characteristics:
       -Start and End of tag
       -May be attributes
       -Body enclosed within tag
       -For example
               < mytag:hello optional_attributes ………… >
                  some body
              </ mytag:hello >

5. how many types of commets are used in JSPs?
Comments are ignored by JSP-to-servlet translator. Two types of comments are possibly used in JSP.
   – HTML comment:
      These comments are shown in browser, means on taking view source of the web page; these sorts
       of comments can be read. Format of HTML comments is like to:
                               <!-- comment text-->
   – JSP comment:
      These comments are not displayed in browser and have format like:
            <%-- comment text --%>

6. Differentiate sleeping and yielding in threads
. sleep(int time) method
    -Causes the currently executing thread to wait for the time (milliseconds) specified
    -Waiting is efficient equivalent to non-busy. The waiting thread will not occupy the processor
    -Threads come out of the sleep when the specified time interval expires or when interrupted by
         some other thread
    -Thread coming out of sleep may go to the running or ready state depending upon the availability of
         the processor. The different states of threads will be discussed later
    -High priority threads should execute sleep method after some time to give low
         priority threads a chance to run otherwise starvation may occur
    -sleep() method can be used for delay purpose i.e. anyone cal call Thread.sleep()method
    -Note that sleep() method can throw InterruptedException. So, you need try-catch block

.yield( ) method
    -Allows any other threads of the same priority to execute (moves itself to the end of the priority
    -If all waiting threads have a lower priority, then the yielding thread resumes execution on the CPU
    -Generally used in cooperative scheduling schemes

3 Marks Questions
1. Why Expression language is used?
Java as the scripting language in JSP scares many people particularly web page designers which have enough
knowledge to work with HTML and some scripting language, faced lot of difficulties in writing some simple
lines of java code. Can we simplify this problem to ease the life of web designer? Yes, by using Expression
Language (EL).
The Expression Language, not a programming or scripting language, provides a way to simplify expressions
in JSP. It is a simple language that is geared towards looking up objects, their properties and performing
simple operations on them. It is inspired form both the ECMAScript and the XPath expression language.

2. why session tracking is used in httpServlets?
Many applications require a series of requests from the same client to be associated with one another. For
example, any online shopping application saves the state of a user's shopping cart across multiple requests.
Web-based applications are responsible for maintaining such state, because HTTP protocol is stateless. To
support applications that need to maintain state, Java Servlet technology provides an API for managing
sessions and allows several mechanisms for implementing sessions.
          2 ans
When there is a series of continuous request and response from a same client to a server, the server cannot
identify from which client it is getting requests. Because HTTP is a stateless protocol.
When there is a need to maintain the conversational state, session tracking is needed. For example, in a
shopping cart application a client keeps on adding items into his cart using multiple requests. When every
request is made, the server should identify in which client’s cart the item is to be added. So in this scenario, there
is a certain need for session tracking.
Solution is, when a client makes a request it should introduce itself by providing unique identifier every time.
There are five different methods to achieve this.
      User authorization
      Hidden fields
      URL rewriting
      Cookies
      Session tracking API

3. EJBs and JSP/servlet run on which server?
Web server is used to execute web pages like JSPs whereas application server is used to run special business
objects like Enterp rise JavaBeans . The web layer and appli cations server can be on two separate machines or
they can be on same.

4. what are streams?
I/O libraries often use the abstraction of a stream, which represents any data source or sink as an object
  capable of producing or receiving pieces of data.

      It is an abstraction of a data source/sink

      • We need abstraction because there are lots of different devices (files, consoles, network,
memory, etc.). We need to talk to the devices in different ways (sequential, random access, by
lines, etc.) Streams make the task easy by acting in the same way for every device. Though inside
handling of devices may be quite different, yet on the surface everything is similar. You might read from a
file, the keyboard, memory       or network         connection,    different devices may require
specialization of the basic stream, but you can treat them all as just "streams". When               you
read from a network, you do nothing different than when you read from a local file or from user's

• So you can consider stream as a data path. Data can flow through this path in one direction
between specified terminal points (your program and file, console, socket etc.)

5. Differentiate layers and tiers
Layers vs. Tiers
Layers are merely logical grouping of the software components that make up the application or
service,whereas Tiers refer to the physical residence of those layers.
In general,
       . Layers – represents the logical view of application
       . Tiers – represents physical view of application

6. What is differences between getRequestDispatcher(String path) method using
javax.servlet.httpServletRequest or using servletContext?

Tag Library – JSTL

Custom Tags ,and format

JSP action Element

There was one numerical type ( for x = 3, y = 5 , then a loop of if ( X<0 || y > 10 ) x = x*y else x = x+ 1

to me it was False , so my option was none in given choices.

How session tracking is done in Servlets ,

Problems of structs ( Complexity and none aval of UI tags I remembered)

HTTP session k step likhne thy detail se

WHAT is validation? Describe build-in validator?

why servlets are used as controller in JSP are never used?

what is JSP? why its used? n also explain JSP framwork?

What is the typical use of Hash table?

Whenever a program wants to store a key value pair, one can use Hashtable.


To top