Академический Документы
Профессиональный Документы
Культура Документы
5/30/2013 0 Comments
client's request parameters. Dynamic Web pages are processed by the server and
then the generated content is sent to the client. They may involve information
from a database or some other information such as client's user name.
__________________SMALL___________
2. What is W3C?
4. What is Extranet?
Answer: Unlike Intranet, Extranet allows outside access to local resources.
CHAPTER-2 (HTML)
1. What is HTML?
Answer: HTML stands for Hypertext Markup Language. It is a layout and format
defining language used to write Web pages. It allows you to:
Publish documents to the Internet in a platform independent format
Create links to related work from your document
Include graphics and multimedia data in your documents
Link to non-World Wide Web information resources on the Internet
An HTML page starts and end with <HTML></HTML> tags, marking the
beginning and end of an HTML page. A page can be divided into the header and
the body. The <HEAD></HEAD> tags represent the former and contain header
information, which is not displayed in the browser window. The <HEAD></HEAD>
tags also contain the <TITLE></TITLE> tags, which contain the text that will be
displayed in the title bar of the browser window when the page is opened.
The <BODY></BODY> tags comprise the body element of an HTML page. The
content with the <BODY></BODY> tags is displayed in the browser window.
3. List down different classifications of tags with 2 examples tags for each
category.
Answer: Tags can be classified as:
Tags for document structure: HTML and HEAD
Heading tags: TITLE and LINK
Block-level text elements: H1 through H6, P
Lists: OL and UL
5. Write an example HTML page containing a table 4 X 3 and each row colored
differently.
Answer: The following is an HTML page containing a table 4 X 3 and each row
colored differently:
<html>
<head>
<title>Colored Table</title>
</head>
<body>
<table border="1" width="100%">
<tr bgcolor="#0000FF">
<td width="33%"> </td>
<td width="33%"> </td>
<td width="34%"> </td>
</tr>
<tr bgcolor="#00A0FF">
<td width="33%"> </td>
<td width="33%"> </td>
<td width="34%"> </td>
</tr>
<tr bgcolor="#AB00FF">
<td width="33%"> </td>
<td width="33%"> </td>
<td width="34%"> </td>
</tr>
<tr bgcolor="#FB2CFF">
<td width="33%"> </td>
<td width="33%"> </td>
<td width="34%"> </td>
</tr>
</table>
</body>
</html>
The above will display the image in the file image_filename.gif. In case this image
cannot be loaded, the text "this is an image loaded from a relative path" will be
displayed.
Similarly, to load an image from a URL, you can specify the URL in the SRC
attribute.
9. Create a simple HTML page to demonstrate usage of anchor tags.
Answer: The following HTML page, demonstrates the usage of anchor tags:
<html>
<head>
<title>Anchor Tag Characteristics</title>
</head>
<body>
<h1 align="center">All in One</h1>
<p align="left">In <A HREF= "#sec1">section 1</a> you can search. In <A
HREF= "#sec2">section 2</a> you can shop.</p>
<A NAME= "sec1">Section 1:
</a>
<p>
<a href="http://google.co.in" target= "_blank">
Search on Google</a> </p>
<p><a href="http://yahoo.com">Search on Yahoo</a></p>
<p> </p>
<p>
<A NAME= "sec2">Section 2: </a>
</p>
<p><a href="http://ebay.com">
Shop on ebay </a></p>
<p><a href="http://wallpapers.com">Download wallpapers</a> </p>
<p><a href="http://t-shirts.com">
Order Custom T-Shirts
News</a></p>
</body>
</html>
Answer: Ordered lists are numbered list and represented by the <OL> tag in
HTML. You can use the tag's TYPE and START attributes to change the style and
sequence of the numbering in the list. The <LI> tag is used for individual items of
the list. Ordered lists are usually used to represent procedures/sequence of steps
in HTML pages. An example of an ordered list is give below:
The unordered list is a bulleted list and represented by the <UL> tag in HTML.
You can use the tag's TYPE attribute to change the style of the bullets in the list.
The <LI> tag is used for individual items of the list. Unordered lists are usually
used to represent various items of a category or related to a topic. An example of
an unordered list is given below:
<UL>
<LI>Dogs</LI>
<LI>Cats</LI>
<LI>Horses</LI>
</UL>
--------------------------------------------------------------------
Answer: <META> tag is a special tag, which is used to provide the information
about the document under which it is embedded. It is primarily used for listing
keywords and summary associated with a Web page. Search engine spiders use
this information while indexing a page.
This will create a hyperlink. When you click on this hyperlink, your default e-mail
client will open with the specified address in the To field.
3. What is SGML?
Answer: SGML or Standardized Generalized Markup Language is, a language and
a standard to define other markup languages. HTML is based upon it
<html>
<head>
<title>Pop up</title>
</head>
<body>
<h1>Trying Pop-ups</h1>
<script language = "JavaScript">
alert("This is an alert message. It uses alert() in JavaScript");
</script>
</body>
</html>
ELEMENT [{property1:value1:property2:value2}]
</style>
Note that the style tag is always placed in the head of the document.
The DOM also provides an interface for dealing with events, allowing you to
capture and respond to user and browser actions.
</head>
<body onclick = "window.status = 'You have clicked!!!'">
<h1>Changing Status Bar Text</h1>
</body>
</html>
7. What is the difference between HTML and DHTML?
Answer: HTML is a markup language used to create static web pages. DHTML on
the other hand is not a language by itself but a combination of different
technologies such as HTML, CSS, JavaScript, and DOM. It is used to create
dynamic pages.
</script>
2. How can you declare array in JavaScript?
Answer: JavaScript has built in Array object, there are two ways for declaring an
array:
5. Using JavaScript how can you determine client's browser name and version?
__________________________________________
After including CGI.pm you can call its functions such as header, which prints the
Content-type header.
If($var==1)
{
$out = "This was one";
}
elseif($var==0)
{
$out = "This was zero";
}
else
{
$out = "Was neither 0 nor 1";
}
print "$out";
The above code will print, "This was one" if the variable $var is 1. Otherwise, if
$var is equal to 0, it will print "This was zero". If $var is nether 1 nor 0, it will print
"Was neither 0 nor 1". Note that the else or elesif part is optional. You can also
have a single if statement in your program or nested ifs and if-else or if-elseif-else
structures.
Note that to compare strings you must use the eq operator. You can also join
multiple conditions using the logical operators. Similar to the If command is the
unless command. For example:
unless($var!=1)
{
$out = "This was one";
}
else
{
$out = "Not one";
}
2.Foreach loop: It is used for iterating over a list of values. The elements of an
array can be iterated over using foreach as:
Foreach my $i(@arr)
{
$arr[$i] = $i; //set the value of each element of array to its index number
}
reinitializer. For example, to perform an action such as printing use the for loop
as:
for($i=0;$i<10;$i++)
{
print "$i";
}
This will print numbers from 0 to 9.
In the above URL, the form field 'username', whose value is 'smith', and field
'password' whose value is 'juyhy', are appended to the URL after '?'. They form
the query string. Query string comprises of name-value pairs. Each name value
pairs is separated by &. Spaces between values are encoded as + and other
special characters are encoded as their ASCII value preceded by a %.
8. What are GET and POST methods? What is the difference between GET and
POST Methods.
Answer: GET and POST are methods of sending data to the server for making it
available to CGI programs. The GET method passes the information through
environment variables whereas the POST method sends the data through
standard input.
9. Write a simple CGI application, which accepts the user information and
displays the Information entered to the user?
Answer:
#!/usr/bin/perl #print "Content-type:text/html\n\n";
#$form = $ENV{'QUERY_STRING'};
use CGI;
$cgi = new CGI;
print $cgi->header;
print $cgi->start_html( "Question Nine" );
$text = $cgi->param( 'text' );
if( $text )
{
print "You entered $text";
}
else
{
print '<form action="ques9.pl" method="get">';
print "</form>":
}
print $cgi->end_html;
Save the file as ques9.pl.
10. Write a CGI application that accepts 3 numbers from the users and displays
the LCM of three numbers using GET and POST methods.
Answer:
#!/usr/bin/perl
#print "Content-type:text/html\n\n";
#$form = $ENV{'QUERY_STRING'};
use CGI;
$cgi = new CGI;
print $cgi->header;
print $cgi->start_html( "Question Ten" );
my $one = $cgi->param( 'one' );
my $two = $cgi->param( 'two' );
my $three = $cgi->param( 'three' );
if( $one && $two && $three )
{
$lcm = &findLCM( &findLCM( $one, $two ), $three );
print "LCM is $lcm";
}
else
{
print '<form action="ques10.pl" method="post"><pre>';
____________________SMALL_______________
1. What is FastCGI?
Answer: FastCGI is an enhancement over CGI. Instead of creating a new process
for every request, FastCGI uses the same process and queues requests to it. It
saves lots of memory but it also forces user to wait for the previous requests to
finish.
3. How can you open a file for writing and appending in PERL?
Answer: For opening a file to write, use:
open( FILE, ">" . file_name )
For opening a file to append, use:
open( FILE, ">>" . file_name )
4. How are functions defined in PERL? How are values passed to them?
Answer: Functions in PERL are defined by preceding them by keyword sub. For
example:
sub hello {
print 'hello';
}
Variable passing is little tricky in PERL. As evident from the above example,
functions do not take any parameters as input. Instead, arguments are passed in
special array variable @_. This can be explained with the help of the following
example make:
sub args
{
my ($msg) = @_;
print $msg;
}
args( "hello" );
localCheck();
printVal();
Output will be
hello
hi
hello
_________________________________________________________
----------------------------------------------------
3. How can you specify a custom error page for a particular server error?
Answer: This can be done by including following code in Web.xml. Error code is
server's internal code. For different error codes, different pages can be specified.
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
_______________________________________________________
CGI is not an efficient solution for developing dynamic Web content. For every
request, the Web server has to create a new operating system process, load an
interpreter and a script, execute the script and then tear it all down again. This is
taxing for the server and affects the scalability of the application.
However, in JSP, each JSP page is compiled into executable code on first request.
On subsequent requests thee executable code is directly invoked instead of
recompilation. This enables a server to handle JSP pages much faster than CGI
programs.
2. Write a JSP programming which displays different message to the user based
on the time of day.
Answer:
<%@ page content language="java" import="java.util.Calendar" %>
<html>
<head><title>Time Message</title></head>
<body>
<%
Calendar cal = Calendar.getInstance();
int hh = cal.get( Calendar.HOUR_OF_DAY );
String message = "";
if( hh < 12 )
{
message = "Good Morning!";
}
else if( hh == 12 )
{
message = "Good Noon!";
}
else if( hh > 12 && hh < 18 )
{
message = "Good Afternoon!";
}
else if( hh > 18 && hh < 21 )
{
message = "Good Evening!";
}
else
{
_______________________SMALL__________________________
For precompiling under tomcat, use jspc command, under bin directory of tomcat
installation as:
Where, DIRJ is the directory where generated java files will be stored.
2. What is JSTL?
Answer: JSTL or Java Server Pages Standard Tag Library is a freely available
collection of custom tags, which provides various functionalities. Some of the
tags are: tags to interact with databases; tags to iterate over collections; and
tags for internationalization of dates and currencies.
3. How van you make the browser to reload the page every N number of
seconds?
Answer: This can be done by adding Refresh header to response. The following
JSP code can be used for this:
<%
response.addHeader( "Refresh", N );
%>
CHAPTER-7 (SERVLETS)
package hallo;
import java.io.*;
import javax.servlet.*;
import. Javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)throws ServletException, IOexception {
PrintWriter out = response.getWriter();
Out.println("Hello World");
}
}
HttpServletResponse object. As a result, from within the servlet, you will able to
write to object stream associated with the network association.
DESstroy: This is the final stage in a servlet lifecycle. In this stage, the destroy()
method is called before shutting down the servlet.
7. Draw a class diagram to show the relationship between major classes in the
servlet API.
Answer: The class diagram is shown as here:
Class Diagram
9. Describe the request handling cycle and the methods invoked on the servlet by
the servlet container.
Answer: Following are the operations done on a servlet by servlet container when
a servlet is requested:
1.If servlet instance does not exist in memory, the container:
a.Loads the servlet class and thus creates its instance
b.Calls the init() method on the above class and passes ServletConfig as
parameter
2.On any further request service() method of servlet class is called and
HttpServletRequest and HttpServletResponse are passed as parameters to it.
11. Which class provides methods of reading the parameters specified in the
deployment descriptor file?
Answer: ServletConfig class provides methods getInitParameter() and
getInitParameterNames() for reading parameters specified in deployment
descriptor.
12. Which streams are used for sending the contents of the entity-body in the
response?
_______________SMALL___________________
1. How can you write messages in server log using servlet API? In Tomcat, logs
are stored in which directory?
Answer: ServletContext can be used for logging messages to the server log. One
of the major advantages of using logging is that while printing an exception, the
complete stack trace is written in the log. Following snippet explains logging:
ServletContext con = getServletContext();
con.log( "logging is good" );
try
{
throw new Exception( "exception" );
}
catch( Exception e )
{
con.log( e ); //will write e.printStackTrace() in log
}
In Tomcat, logs are stored in logs directory.
2. While sending a file from a servlet response, which header should be set to tell
the browser that it should prompt user to save this file and not to display it in
browser window?
Answer: Content-Disposition header is required to be set for this purpose as:
response.addHeader( "Content-Disposition","attachment; filename=" +
filename_to_save );
-Using applications
2. Explain in brief how to use hidden controls in a web page? Give an example.
Answer: Using HTML, hidden controls are an easy way to store data in a Web
page. You can store data in a hidden control and then refer to the value of control
wherever required. Hidden controls are often used when you submit a form to
itself. That is if your form's ACTION attribute is set to the same page which
contains the form. In this case, every time the page loads you have to determine
whether it is being loaded afresh or after a submission. For this, you can store a
text value such as "DONE" in a hidden control SUBMIT_STATUS, and check for it
whenever the page loads. If request.getParameter(SUBMIT_STATUS) returns a
NULL value, it means that the form is being loaded afresh.
%>
</body>
</html>
int SC_ACCEPTED: Indicates that a request was accepted for processing but was
not completed
int SC_BAD_GATEWAY: Indicates that the HTTP server received an invalid
response from a server, when acting as a proxy or gateway
int SC_BAD_REQUEST: Indicates that the request sent by the client was incorrect
int SC_CONFLICT: Indicates that the request cannot be completed because of a
conflict with the current state of the resource
int SC_CONTINUE: Indicates that the client can continue
9. What is a session?
Answer: Sessions let you preserve data between accesses to a Web page by the
same user. Unlike cookie, sessions are stored on the server itself in files or
databases.
10. Explain in brief how to track a user using Sessions with an example.
Answer: You can track user using sessions by storing the details of his/her session
with the Web site. For example, you store the number of times that a user has
visited a page and display it to him on every visit. To track the user using
sessions perform the following steps:
1.Include page directive with the session attribute set to true, at the top of the
page, to indicate that a new session has to be started(if one does not already
exist).
2.Check whether a count has already been set before in a session attribute using
the getAttribute() method of the Session class.
3.If the count has not been set, the getAttribute() method will return null. In that
case, you can create a new count value. If a value already exists, you can
increment it and store the new value in the session object.
The above steps are implemented in the following code:
<%
Integer count = (Integer)session.getAttribute("visitcount");
If(count==null)
{count = new Integer(1);
}
else
{
count = new Integer(visitcount.intValue()+1);
}
session.setAttribute("visitcount", count);
%>
<body>
You have visited this page <%=count%> times.
</body>
Answer: A single session allows you to track one user at a time whereas an
application enables you to track all JSPs in the same site, regardless of the
number of users accessing them.
_____________SMALL_____________________
1. How can you set session time out programmatically? What is the advantage of
it?
Answer: Session timeout can be set individually by calling setMaxInavtiveInterval(
time_in_seconds ) on the HttpSession object of a particular session. Timeout
setting in web.xml is universal. By using the above function call timeouts can be
set according to user role.
3. What is Locale? How can you obtain client's Locale in using servlet API?
Answer: Locale is the user's top preference for language stored in the browser.
This information can be crucial for some web applications. For example, using this
information, web application can provide interface elements in client's preferred
language that is, it can behave like an automated multilingual software.
Throwable throwable =
(Throwable)request.getAttribute("javax.servlet.error.exception");
Integer status_code =
((Integer)request.getAttribute("javax.servlet.error.status_code"));.
5. Explain a practical use of redirecting. How can you redirect a client using
servlet API?
Answer: Redirecting is used in many phases of web application, logout module is
one such phase. Here, all session information is invalidated, database
connections are released, and client is then redirected to application's home
page. To redirect a user using servlet, API uses:
response.sendRedirect( page_url_to_redirect );
Redirection causes client to send a request for the page specified as input in
above call.
_____________________________________________________
The main role of SSL is to provide security for Web traffic. Security includes
confidentiality, message integrity, and authentication. SSL achieves these
elements of security through the use of cryptography, digital signatures, and
certificates.
Many vendor application servers conform to the J2EE specification allowing you
to select a best-of-breed solution.
To handle fluctuations in resource demand server-side resources can easily be
scaled by adding or removing servers.
Application servers provide access to complex services, such as transaction and
security management, resource pooling, JNDI (Java Naming and Directory
Interface), and component lifecycle management.Following are the
disadvantages of EJBs:
EJB has a large and complicated specification.
EJBs take time to develop. Also, they are difficult to debug. Occasionally, the bug
may not be in your code but in the application server itself.
Frequently released newer versions of EJB specifications render application
obsolete quickly.
Session beans are different from entity beans in that they are not permanent
objects. They are not shareable in general although it is possible to share them
using handles. Session beans can be used to distribute and isolate processing
tasks. Each session bean can be used to perform a certain task on behalf of its
client. The tasks can be distributed on different machines. Session beans also do
not have a primary key. Unlike entity beans, session beans are not primarily
meant to be shared or found later.
8. What is DTD?
Answer: DTD or Document Type Definitions is a document that contains grammar
rules for validating an XML document. It is a schema specification method for
XML.
__________________-SMALL-_____________________
1. What is JNDI?
Answer: JNDI or Java Naming and Directory Interface is a set of APIs that can be
used to access the naming and directory services. Server side technologies such
as EJB use JNDI for storing objects for later use and also for lookup operations.
2. What is XSLT?
Answer: XSLT or Extensible Stylesheet Language Transformation is used to
convert either one xml document into another (such as a subset) or to convert
xml data into presentable HTML page.
-----------------(END)------------------