NOV/DEC 2008 ANS 1 (A) Fill in The Blanks
NOV/DEC 2008 ANS 1 (A) Fill in The Blanks
4.To persist information of user on client computer for a period of days or years
cookie is used.
7. Flush method of response object is used to send all the data store3d in the
buffer to client and then clears the buffer in ASP buffered approach.
8. Application object is used to share information among several clients visiting
the same group of pages in ASP.
9. For applying rules for structuring an XML document DTD is used.
ANS 2 B: <HTML>
<HEAD>
<title>Politics<title>
</HEAD>
<body>
<h1><U>Political Information</U></h1>
<table border=”1”>
<tr>
<td><U>Name:</U></td>
<td><input type=“text“ Name=“txtName“>
</td>
</tr>
<tr>
<td>Gender:</td>
<td><input type=“Radio“ Name=“Gender“ value=”Male” >Male
<input type=“Radio“ Name=“Gender“ value=”Female” >Female
</td>
</tr>
<tr><td>Party</td>
<td><input type=”text” Nmae=”txtParty”></td>
<tr><td colspan=”2”><input type=”submit” Name=”submit” value=”Add”>
</tr>
</table>
</form>
<% If Request(“submit”)<>” then
qr=”insert into Political_Info values(‘ ” & Request(“txtName”) & ” ’,’ ” &
Request(“Gender”) & ” ‘,’ “ &Request(“txtParty”)& “ ‘)”
cn.execute qr
%>
</body>
</html>
ANS 3(1)
ASP script
<%
today = cint(day(date))
Response.Write(today)
if today MOD 2 = 0 then
Response.Redirect("even.asp")
else
Response.Redirect("odd.asp")
end if
%>
ANS 3(2)
A cookie is often used to identify a user. A cookie is a small file that the
server embeds on the user's computer. Each time the same computer
requests a page with a browser, it will send the cookie too. With ASP, you
can both create and retrieve cookie values.
Create cookie
<%
Response.Cookies("firstname")="Alex"
%>
Retive cookie:
<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>
ANS 3(4) :
<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>
ANS 3(5) :
This control uses an XML file to store the ad information. The XML file must begin and
end with an <Advertisements> tag. Inside the <Advertisements> tag there may be
several <Ad> tags which defines The predefined elements inside the <Ad> tag are listed
below:
Element Description
<ImageUrl> Optional. The path to the image file
<NavigateUrl> Optional. The URL to link to if the user clicks the ad
<AlternateText> Optional. An alternate text for the image
<Keyword> Optional. A category for the ad
<Impressions> Optional. The display rates in percent of the hits
Property:
The AdvertisementFile property is used to set or return the path to the XML file
that contains the advertisement data.
<asp:AdRotator AdvertisementFile="path" runat="server" />
Path: A string specifying the location of the XML file that contains the
advertisement data
Example
<form runat="server">
<asp:AdRotator id="ad1" runat="server"
AdvertisementFile="Ad1.xml" />
</form>
SECTION II
ANS 4 (A) 1.
ANS 4 (A) 2.
URL encoding: it converts characters into a format that can be transmitted over the
Internet. URLs can only be sent over the Internet using the ASCII character-set.
Since URLs often contain characters outside the ASCII set, the URL has to be
converted into a valid ASCII format.
URL encoding replaces unsafe ASCII characters with a "%" followed by two
hexadecimal digits.
URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.
Example:
Some+website+you+got%21
a.Servlet Context :
In servlet programming, the servlet context is the environment where the servlet runs.
The servlet container creates a ServletContext object that you can use to access
information about the servlet's environment.
ServletConfig:
A servlet configuration object used by a servlet container used to pass information to
a servlet during initialization.
b. Servlet config is a private area for every servlet.Any variable stored there is
accessible to only that servlet while sevlet context is a shared area for every servlet in
an application.In an aaplication every servlet can access the variable stored in servlet
context.
c. servlet context hold the info about application and servlet config hold the servlet
info.
e The ServletConfig parameters are specified for a particular servlet and are
unknown to otherservlets.
ANS 4 (A) 4.
Certain objects that are available for the use in JSP documents without being declared
first. These objects are parsed by the JSP engine and inserted into the generated servlet.
The implicit objects re listed below
request
response
pageContext
session
application
out
config
page
exception
ANS 4 (A) 5.
JavaBeans are reusable software components for Java that can be manipulated
visually in a builder tool.Practically, they are classes written in the Java programming
language conforming to a particular convention. They are used to encapsulate many
objects into a single object (the bean), so that the bean can be passed around rather
than the individual objects.
ANS 5(A)
JSP vs ASP
1. JSP and ASP are both server side scripting languages
2. JSP is from Sun Microsystems while ASP is from Microsoft
3. ASP costs money while JSP is free.
4. ASP code is interpreted while JSP code is compiled at run time
5. JSP code can run faster than ASP if there are fewer changes
6. Majority of Windows users use ASP while users of open source operating systems
like Linux use JSP among others.
ComDescriptio ASP
JSP
n
Writing HTML Response.Write "Some
out.print("Some HTML code");
code HTML code"
Obtaining a Request("parameterName"
request.getParameter("parameterName
parameter )
")
value
Null value null Nothings
Web Server Microsoft IIS or Personal Web Server Any Web server, including Apache,
Netscape, and IIS
OR
ANS 5 (A)
The pattern isolates "domain logic" (the application logic for the user) from the user
interface(input and presentation), permitting independent development, testing and
maintenance of each.
Introduction to MVC(Model View Controler)
Struts : Struts is an open source framework from Jakartha Project designed for
developing the web applications with Java SERVLET API and Java Server Pages
Technologies.Struts conforms the Model View Controller design pattern. Struts
package provides unified reusable components (such as action servlet) to build the
user interface that can be applied to any web connection. It encourages software
development following the MVC design pattern.
* The Model maintains the state and data that the application represents .
* The View allows the display of information about the model to the user.
Example: Example
Model
The model is a collection of Java classes that form a software application
intended to store, and optionally separate, data. A single front end class that
can communicate with any user interface (for example: a console, a graphical
user interface, or a web application).
View
The view is represented by a JavaServer Page, with data being transported to
the page in the HttpServletRequest or HttpSession.
Controller
The Controller servlet communicates with the front end of the model and loads
the HttpServletRequest or HttpSession with appropriate data, before
forwarding the HttpServletRequest and Response to the JSP using a
RequestDispatcher.
The Servlet is a Java class, and it communicates and interacts with the model, but
does not need to generate HTML or XHTML output; the JSPs do not have to
communicate with the model because the Servlet provides them with the information
—they can concentrate on creating output.
In Struts, the view is handled by JSPs and presentation components, the model is
represented by Java Beans and the controller uses Servlets to perform its action.
By developing a familiar Web-based shopping cart, you'll learn how to utilize the
Model-View-Controller (MVC) design pattern and truly separate presentation from
content when using Java Server Pages.
Many web applications are JSP-only or Servlets-only. With JSP, Java code is
embedded in the HTML code; with Servlets the Java code calls println methods to
generate the HTML code. Both approaches have their advantages and drawbacks;
Struts gathers their strengths to get the best of their association.
View on JSP
The early JSP specification follows two approaches for building applications using
JSP technology. These two approaches are called as JSP Model 1 and JSP Model 2
architectures.
ANS 5 (B)
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
ANS 6 (1).
Implicit objects in jsp are the objects that are created by the container automatically and
the container makes them available to the developers, the developer do not need to
create them explicitly.
There are nine implicit objects. Here is the list of all the implicit objects:
Object Class
javax.servlet.ServletConte
application
xt
javax.servlet.ServletConfi
Config
g
exception java.lang.Throwable
javax.servlet.jsp.JspWrite
Out
r
Page java.lang.Object
PageConte javax.servlet.jsp.PageCon
xt text
javax.servlet.ServletRequ
Request
est
javax.servlet.ServletResp
response
onse
javax.servlet.http.HttpSes
Session
sion
ANS 6 (2).
javax.servlet.GenericServlet
Signature: public abstract class GenericServlet extends java.lang.Object
implements Servlet, ServletConfig, java.io.Serializable
javax.servlet.http.HttpServlet
Signature: public abstract class HttpServlet extends GenericServlet implements
java.io.Serializable
ANS 6 (3)
GET Method:
1. All the name value pairs are submitted as a query string in URL.
2. It's not secured as it is visible in plain text format in the Location bar of the web
browser.
3. As the data transfers through address bar (URL) there are some restrictions in
using space, some characters like ampersand (&) etc in the GET method of
posting data. We have to take special care for encoding data if such special
characters are present.
4. Length of the string is restricted.
5. If method is not mentioned in the Form tag, this is the default method used.
6. If get method is used and if the page is refreshed it would not prompt before the
request is submitted again.
7. One can store the name value pairs as bookmark and directly be used while
sharing with others - example search results.
8. Data is always submitted in the form of text
9. If the response of the page is always same for the posted query then use GET
example database searches
POST Method:
1. All the name value pairs are submitted in the Message Body of the request.
2. Length of the string (amount of data submitted) is not restricted.
3. Post Method is secured because Name-Value pairs cannot be seen in location
bar of the web browser.
4. If post method is used and if the page is refreshed it would prompt before the
request is resubmitted.
5. If the service associated with the processing of a form has side effects (for
example, modification of a database or subscription to a service), the method
should be POST.
6. Data is submitted in the form as specified in enctype attribute of form tag and
thus files can be used in FileUpload input box.
ANS 6 (4)