Exam Practices

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

WEB TECHNOLOGY REVISION FOR UNIVERSITY EXAMS

HTML
HTML stands for Hyper Text Markup Language. HTML is the standard
markup language for creating Web pages. HTML describes the structure
of a Web page. HTML consists of a series of elements. HTML elements tell
the browser how to display the content.

HTML PROGRAM FOR CUSTOMERS


<!DOCTYPE html>
<html>
<head>
<title>Customers</title>
<meta charset="UTF-8">
<link href="site.css" rel="stylesheet">
</head>

<body>
<div id="main">
<h1>Customers</h1>
<table>
<tr>
<th>Name</th>
<th>City</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Berlin</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbköp</td>
<td>Luleå</td>
<td>Sweden</td>
</tr>
</table>
<footer id="foot01"></footer>
</div>
<script src="script.js"></script>

</body>
</html>

CASCADING STYLE SHEETS :


CSS is a stylesheet language that describes the presentation of an HTML (or
XML) document.

CSS describes how elements must be rendered on screen, on paper, or in


other media.

body {
font-family: "Trebuchet MS", Verdana, sans-serif;
font-size: 16px;
background-color: dimgrey;
color: #696969;
padding: 3px;
}

#main {
padding: 5px;
padding-left: 15px;
padding-right: 15px;
background-color: #ffffff;
border-radius: 0 0 5px 5px;
}

h1 {
font-family: Georgia, serif;
border-bottom: 3px solid #cc9900;
color: #996600;
font-size: 30px;
}
JAVASCRIPT EXAMPLES

1. HTML to define the content of web pages

2. CSS to specify the layout of web pages

3. JavaScript to program the behavior of web pages

Java script example:

<html>

<head>

<title>Event!!!</title>

<script type="text/javascript">

function trigger()

document.getElementById("hover").addEventListener("mouseover", popup);

function popup()

alert("Welcome to my WebPage!!!");

</script>

<style>

font-size:50px;
position: fixed;

left: 550px;

top: 300px;

</style>

</head>

<body onload="trigger();">

<p id="hover">Welcome!!!</p>

</body>

</html>

XML PROGRAMS

XML stands for eXtensible Markup Language.

XML was designed to store and transport data.

XML was designed to be both human- and machine-readable.


XSLT
XSLT stands for Extensible Stylesheet Language Transformation.
 XSLT is used to transform XML document from one form to another form.
 XSLT uses Xpath to perform matching of nodes to perform these
transformation .
 The result of applying XSLT to XML document could be an another XML
document, HTML, text or any another document from technology
perspective.
 The XSL code is written within the XML document with the extension
of (.xsl).
 In other words, an XSLT document is a different kind of XML document.

 Xpath is an important component of XSLT standard.


 Xpath is used to traverse the element and attributes of an XML document.
 Xpath uses different types of expression to retrieve relevant information from
the XML document.
 Xpath contains a library of standard functions.

<?xml version="1.0" encoding="UTF-8"?>


<?xml-stylesheet type="text/xsl "href="Rule.xsl" ?>
<student>
<s>
<name> Divyank Singh Sikarwar </name>
<branch> CSE</branch>
<age>18</age>
<city> Agra </city>
</s>
<s>
<name> Aniket Chauhan </name>
<branch> CSE</branch>
<age> 20</age>
<city> Shahjahanpur </city>
</s>
<s>
<name> Simran Agarwal</name>
<branch> CSE</branch>
<age> 23</age>
<city> Buland Shar</city>
</s>
<s>
<name> Abhay Chauhan</name>
<branch> CSE</branch>
<age> 17</age>
<city> Shahjahanpur</city>
</s>
<s>
<name> Himanshu Bhatia</name>
<branch> IT</branch>
<age> 25</age>
<city> Indore</city>
</s>
</student>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform ">
<xsl:template match="/">
<html>
<body>
<h1 align="center">Students' Basic Details</h1>
<table border="3" align="center" >
<tr>
<th>Name</th>
<th>Branch</th>
<th>Age</th>
<th>City</th>
</tr>
<xsl:for-each select="student/s">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="branch"/></td>
<td><xsl:value-of select="age"/></td>
<td><xsl:value-of select="city"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

XSLT Elements
o #1) <xsl:stylesheet> OR<xsl:transform>
o #2) <xsl:template>
o #3) <xsl:apply-templates>
o #4) <xsl:call-template>
o #5) <xsl:value-of>
o #6) <xsl:for-each>: Repetition
o #7) <xsl:if>: Conditional Processing
o #8) <xsl:choose>: Alternatives condition processing
o #9) <xsl:copy>
o #10) <xsl:copy-of>
o #11) <xsl:comment>
o #12) <xsl:text>
o #13) <xsl:element>
o #14) <xsl:attribute>
o #15) <xsl:sort>
o #16) <xsl:variable>
o #17) <xsl:Key>
o #18) <xsl:message>
o #19) <xsl:param>&<xsl:with-param>
o #20) <xsl:import>
o #21) <xsl:include>
o #22)<xsl:output>
o #23) <xsl:strip-space>
o #24) <xsl:preserve-space>

Books.xml

<?xml version="1.0" encoding="UTF-8"?>


<store> <!-- Root Element -->
<book id ="5350192956">
<bookname>XSLT Programmer's Reference</bookname>
<authorname>Michael Kay</authorname>
<publisher>Wrox</publisher>
<price>$40</price>
<edition>4th</edition>
</book>
<book id ="3741122298">
<bookname>Head First Java</bookname>
<authorname>Kathy Sierra</authorname>
<publisher>O'reilly</publisher>
<price>$19</price>
<edition>1st</edition>
</book>
<book id ="9987436700">
<bookname>SQL The Complete Reference</bookname>
<authorname>James R. Groff</authorname>
<publisher>McGraw-Hill</publisher>
<price>$45</price>
<edition>3rd</edition>
</book>
</store>

XSLT is a language for transforming XML documents.

XPath is a language for navigating in XML documents.

XQuery is a language for querying XML documents.

Book example -XSLT


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match = "/">
<html>
<body>
<h2>Books:-</h2>
<table border = "1">
<tr bgcolor = "#cd8932">
<th>Book ID</th>
<th>Book Name</th>
<th>Author Name</th>
<th>Publisher</th>
<th>Price</th>
<th>Edition</th>
</tr>
<xsl:for-each select="store/book">
<tr bgcolor = "#84cd32">
<td><xsl:value-of select = "@id"/></td>
<td><xsl:value-of select = "bookname"/></td>
<td><xsl:value-of select = "authorname"/></td>
<td><xsl:value-of select = "publisher"/></td>
<td><xsl:value-of select = "price"/></td>
<td><xsl:value-of select = "edition"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Servlet program
1. <web-app>
2.
3. <servlet>
4. <servlet-name>sonoojaiswal</servlet-name>
5. <servlet-class>DemoServlet</servlet-class>
6. </servlet>
7.
8. <servlet-mapping>
9. <servlet-name>sonoojaiswal</servlet-name>
10. <url-pattern>/welcome</url-pattern>
11. </servlet-mapping>
12.
13. </web-app>

<web-app> represents the whole application.


<servlet> is sub element of <web-app> and represents the servlet.
<servlet-name> is sub element of <servlet> represents the name of the servlet.
<servlet-class> is sub element of <servlet> represents the class of the servlet.
<servlet-mapping> is sub element of <web-app>. It is used to map the servlet.
<url-pattern> is sub element of <servlet-mapping>. This pattern is used at client side
invoke the servlet.

JAVA SERVER PAGES(jsp)

Java Server Pages (JSP) is a programming tool on the application server


side that supports platform-independent and dynamic methods to construct
Web-based applications.

SimpleDateFormat is a specific class for locale-sensitive encoding and


parsing of dates. SimpleDateFormat lets you begin by choosing some user-
defined date-time configuration styles.

<%@ page import = "java.io.*,java.util.*, javax.servlet.*" %>

<html>

<head>

<title>Display Current Date & Time</title>

</head>
<body>

<center>

<h1>Display Current Date & Time</h1>

</center>

<%

Date date = new Date();

out.print( "<h2 align = \"center\">" +date.toString()+"</h2>");

%>

</body>

</html>

A JSP website that uses the programme to collect the amount of hits. We are
counting the number of hits to a JSP page using the implicit object of the
application in this case.

COUNTER.JSP

<%@ page import="java.io.*,java.util.*" %>

<html>

<head>

<title>Application Implicit Object Example</title>

</head>

<body>
<%

//Comment: This would return null for the first time

Integer counter= (Integer)application.getAttribute("numberOfVisits");

if( counter ==null || counter == 0 ){

//Comment: For the very first Visitor

counter = 1;

}else{

//Comment: For Others

counter = counter+ 1;

application.setAttribute("numberOfVisits", counter);

%>

<h3>Total number of hits to this Page is: <%= counter%></h3>

</body>

</html>

You might also like