CS8651 Notes 005-3 Edubuzz360
CS8651 Notes 005-3 Edubuzz360
CS8651 Notes 005-3 Edubuzz360
com
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
In URL rewriting, we append a token or identifier to the URL of the next Servlet or the
next resource. We can send parameter name/value pairs using the following format:
4. url?name1=value1&name2=value2&??
A name and a value is separated using an equal = sign, a parameter name/value pair is
separated from another parameter using the ampersand(&). When the user clicks the
hyperlink, the parameter name/value pairs will be passed to the server. From a Servlet,
we can use getParameter() method to obtain a parameter value.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
URL Rewriting
Example 7-2 shows a revised version of our shopping cart viewer that uses
URL rewriting in the form of extra path information to anonymously track a
shopping cart.
Example 7-2. Session tracking using URL rewriting import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShoppingCartViewerRewrite extends HttpServlet { public void
doGet(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException { res.setContentType("text/html");
PrintWriter out = res.getWriter(); out.println(""); out.println("");
// Get the current session ID, or generate one if necessary
String sessionid = req.getPathInfo();
if (sessionid == null)
{ sessionid = generateSessionId();
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
}
// Cart items are associated with the session ID
String[] items = getItemsFromCart(sessionid);
// Print the current cart items.
out.println("You currently have the following items in your cart:
");
if (items == null) { out.println("None"); } else { out.println("
");
for (int i = 0; i < items.length; i++)
{ out.println("
"); }
// Ask if the user wants to add more items or check out. // Include the session
ID in the action URL.
out.println("
");
out.println("Would you like to
");
\ \
out.println(" "); out.println(" "); out.println("
");
out.println(""); }
// Not implemented }
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
class designed specifically for this. The session ID is used to fetch and
display the current items in the cart. The ID is then added to the form's
ACTION attribute, so it can be retrieved by the ShoppingCart servlet.
The session ID is also added to a new help URL that invokes the Help
servlet. This wasn't possible with hidden form fields because the Help
servlet isn't the target of a form submission. docstore.mik.ua/orelly/java-
ent/servlet/ch07_03.htm
Compare GET and POST request type.
GET POST
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Servlet interface needs to be implemented for creating any servlet (either directly or
indirectly).
It provides 3 life cycle methods that are used to initialize the servlet, to service the requests,
and to destroy the servlet and 2 non-life cycle methods.
There are 5 methods in Servlet interface. The init, service and destroy are the life cycle methods of
servlet. These are invoked by the web container.
Method Description
File: First.java
1. import java.io.*;
2. import javax.servlet.*;
3.
4. public class First implements Servlet{
5. ServletConfig config=null;
6.
7. public void init(ServletConfig config){
8. this.config=config;
9. System.out.println("servlet is initialized");
10. }
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
11.
12. public void service(ServletRequest req,ServletResponse res)
13. throws IOException,ServletException{
14.
15. res.setContentType("text/html");
16.
17. PrintWriter out=res.getWriter();
18. out.print("<html><body>");
19. out.print("<b>hello simple servlet</b>");
20. out.print("</body></html>");
21.
22. }
23. public void destroy(){System.out.println("servlet is destroyed");}
24. public ServletConfig getServletConfig(){return config;}
25. public String getServletInfo(){return "copyright 2007-1010";}
26.
27. }
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
As displayed in the above diagram, there are three states of a servlet: new, ready and end. The servlet is in
new state if servlet instance is created. After invoking the init() method, Servlet comes in the ready state.
In the ready state, servlet performs all the tasks. When the web container invokes the destroy() method, it
shifts to the end state.
Show the use of ‘param’ variable in JSP.
Jsp param
<jsp:param> tag is used to represent parameter value during jsp forward or include action
When an include or forward element is invoked, the original request object is provided to
the target page. If you wish to provide additional data to that page, you can append
Syntax
8.
Example
<jsp:include page="contact.jsp"/>
<jsp:param name="param1" value="value1"/>
</jsp:include>
Example
<jsp:forward page="home.jsp"/>
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
A cookie is a small piece of information that is persisted between the multiple client
requests.
A cookie has a name, a single value, and optional attributes such as a comment, path and
domain qualifiers, a maximum age, and a version number.
Types of Cookie
9. 1. Non-persistent cookie
2. Persistent cookie
Non-persistent cookie
It is valid for single session only. It is removed each time when user closes the browser.
Persistent cookie
It is valid for multiple session . It is not removed each time when user closes the
browser. It is removed only if user logout or signout.
Advantage of Cookies
Disadvantage of Cookies
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
1. <html>
2. <body>
3. <% out.print("welcome to jsp"); %>
4. </body>
5. </html>
1. Example
11. <div>
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
var elmnt = document.getElementById("p1");
elmnt.remove();
</script>
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
JavaServer Pages (JSP) is a technology for developing Webpages that supports dynamic
content. This helps developers insert java code in HTML pages by making use of special
JSP tags, most of which start with <% and end with %>.
A JavaServer Pages component is a type of Java servlet that is designed to fulfill the role
of a user interface for a Java web application. Web developers write JSPs as text files that
combine HTML or XHTML code, XML elements, and embedded JSP actions and
commands.
Using JSP, you can collect input from users through Webpage forms, present records
from a database or another source, and create Webpages dynamically.
JSP tags can be used for a variety of purposes, such as retrieving information from a
database or registering user preferences, accessing JavaBeans components, passing
control between pages, and sharing information between requests, pages etc.
1. Being an extension to Java servlet, it can use every feature of Java Servlet. Also,
3. The tags which are used are easy to understand and write.
4. Supports Java API’s which can now be easily used and integrated with the
13.
HTML code.
5. The results which are obtained are in HTML format, so can be opened on any
browsers.
7. Changes can be added into the business logic page rather than changing in each
and every page.
Rewrite the code segment to store current server time in session using
Java Servlet API.
The most important advantage of using Servlet is that we can use all the
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Below program shows how to print the current date and time. We can
use simple Date object with toString() to print current date and time.
DateSrv.java
import java.io.*;
import javax.servlet.*;
Output:
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
SERVLET JSP
written purely on Java. another way, we can say that JSPs are
programming.
Servlets run faster than JSP JSP runs slower because it has the transition
Executes inside a Web server, such as A JSP program is compiled into a Java servlet
lifecycle.
Receives HTTP requests from users and Easier to write than servlets as it is similar to
We can not build any custom tags One of the key advantage is we can build
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
2. Simplicity : Run inside controlled server 3. Reading and sending HTML headers.
environment. No specific client software is 4. Parsing and decoding HTML form data.
In brief, it can be defined as Servlet are the java programs that run on a Web
server and act as a middle layer between a request coming from HTTP client and
databases or applications on the HTTP server.While JSP is simply a text
document that contains two types of text: static text which is predefined and
dynamic text which is rendered after server response is received.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
MVC In contrast to MVC On the other hand, JSP plays the role of
we can state view to render the response returned by the
servlet as a servlet.
controller which
2
receives the
request process
and send back the
response.
Request type Servlets can accept JSP on the other hand is compatible with
and process all HTTP request only.
3
type of protocol
requests.
Performance Servlet is faster JSP is slower than Servlet because first the
5 than JSP. translation of JSP to java code is taking
place and then compiles.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
16.
In this figure you can see, a client sends a request to the server and the server
generates the response, analyses it and sends the response to the client.
Stages of the Servlet Life Cycle: The Servlet life cycle mainly goes through four
stages,
Loading a Servlet.
Initializing the Servlet.
Request handling
Destroying the Servlet.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
1. Loading a Servlet: The first stage of the Servlet life cycle involves loading
and initializing the Servlet by the Servlet container. The Web container or
Servlet Container can load the Servlet at either of the following two stages
:Initializing the context, on configuring the Servlet with a zero or positive
integer value.If the Servlet is not preceding the stage, it may delay the
loading process until the Web container determines that this Servlet is
needed to service a request.
2. Initializing a Servlet: After the Servlet is instantiated successfully, the
Servlet container initializes the instantiated Servlet object. The container
initializes the Servlet object by invoking the init(ServletConfig) method
which accepts ServletConfig object reference as a parameter.
3. Handling request: After initialization, the Servlet instance is ready to serve
the client requests. The Servlet container performs the following
operations when the Servlet instance is located to service a request :It
creates the ServletRequest and ServletResponse. In this case, if this is an
HTTP request then the Web container
creates HttpServletRequest and HttpServletResponse objects which are
subtypes of the ServletRequest and ServletResponse objects
respectively.
4. Destroying a Servlet: When a Servlet container decides to destroy the
Servlet, it performs the following operations,It allows all the threads
currently running in the service method of the Servlet instance to complete
their jobs and get released.After currently running threads have completed
their jobs, the Servlet container calls the destroy() method on the Servlet
instance.
After the destroy() method is executed, the Servlet container releases all the
references of this Servlet instance so that it becomes eligible for garbage collection.
Define JDBC.
What is JDBC?
JDBC stands for Java Database Connectivity, which is a standard Java API for
database-independent connectivity between the Java programming language
and a wide range of databases.
17. The JDBC library includes APIs for each of the tasks mentioned below that are
commonly associated with database usage.
Making a connection to a database.
Creating SQL or MySQL statements.
Executing SQL or MySQL queries in the database.
Viewing & Modifying the resulting records.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Formulate the three methods that are central to the life cycle of the servlet.
A servlet life cycle can be defined as the entire process from its creation till the
destruction. The following are the paths followed by a servlet.
The servlet is initialized by calling the init() method.
The servlet calls service() method to process a client's request.
The servlet is terminated by calling the destroy() method.
Finally, servlet is garbage collected by the garbage collector of the JVM.
Now let us discuss the life cycle methods in detail.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
SERVLET JSP
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
presentation logic in just one In JSP business logic is separated from presentation
includes reloading, recompiling JSP modification is fast, just need to click the
A. Advantage of JSTL
1. Fast Development JSTL provides many tags that simplify the JSP.
20.
2. Code Reusability We can use the JSTL tags on various pages.
3. No need to use scriptlet tag It avoids the use of scriptlet tag.
B. JSTL Tags
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Core tags The JSTL core tag provide variable support, URL management, flow
control, etc. The URL for the core tag
is http://java.sun.com/jsp/jstl/core. The prefix of core tag is c.
Function The functions tags provide support for string manipulation and string
tags length. The URL for the functions tags
is http://java.sun.com/jsp/jstl/functions and prefix is fn.
Formatting The Formatting tags provide support for message formatting, number
tags date formatting, etc. The URL for the Formatting tags
is http://java.sun.com/jsp/jstl/fmt and prefix is fmt.
XML tags The XML tags provide flow control, transformation, etc. The URL for t
XML tags is http://java.sun.com/jsp/jstl/xml and prefix is x.
SQL tags The JSTL SQL tags provide SQL support. The URL for the SQL tags
is http://java.sun.com/jsp/jstl/sql and prefix is sql.
PART-B
Questions
Q.No
(i) Integrate how servlets work and its life cycle.
function factorial(x)
{
if (x === 0)
{
2. return 1;
}
return x * factorial(x-1);
}
console.log(factorial(5));
OUTPUT : 120
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
GET POST
5) Get request is more Post request is less efficient and used less
efficient and used more than than get.
Post.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Servlets read the explicit data sent by the clients (browsers). This includes an
HTML form on a Web page or it could also come from an applet or a custom
HTTP client program.
Read the implicit HTTP request data sent by the clients (browsers). This
includes cookies, media types and compression schemes the browser
understands, and so forth.
Process the data and generate the results. This process may require talking
to a database, executing an RMI or CORBA call, invoking a Web service, or
computing the response directly.
Send the explicit data (i.e., the document) to the clients (browsers). This
document can be sent in a variety of formats, including text (HTML or XML),
binary (GIF images), Excel, etc.
Send the implicit HTTP response to the clients (browsers). This includes
telling the browsers or other clients what type of document is being returned
(e.g., HTML), setting cookies and caching parameters, and other such tasks.
Servlet API:
Servelt API contains three packages
javax.servlet: Package contains a number of classes and interfaces that
describe the contract
between a servlet class and the runtime environment provided for an
instance of such a class a
conforming servelt container.
javax.servlet.aanotation: Package contains a number of annotations that
allow users to use
annotations to declare servlets , filters, listeners and specify the metadata for
the declared component
javax.servlet.http: Package contains a number of classes and interfaces
that describe and define the contract between a servlet class rnning under
the HTTP protocal and the runtime environment provided for an instance of
such class by a confirming servlet container.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
1. Cookies
3. URL Rewriting
4. HttpSession
Session is used to store everything that we can get from the client from all the
requests the client makes.
5.
A. How Session Works
B.
he basic concept behind session is, whenever a user starts using our
application, we can save a unique identification information about him, in an
object which is available throughout the application, until its destroyed. So
wherever the user goes, we will always have his information and we can
always manage which user is doing what. Whenever a user wants to exit from
your application, destroy the object with his information.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
A. Advantage of JSTL
1. Fast Development JSTL provides many tags that simplify the JSP.
2. Code Reusability We can use the JSTL tags on various pages.
3. No need to use scriptlet tag It avoids the use of scriptlet tag.
B. JSTL Tags
Core tags The JSTL core tag provide variable support, URL management, flow
etc. The URL for the core tag is http://java.sun.com/jsp/jstl/co
6. prefix of core tag is c.
Function The functions tags provide support for string manipulation and strin
tags The URL for the functions tags
is http://java.sun.com/jsp/jstl/functions and prefix is fn.
Formatting The Formatting tags provide support for message formatting, numb
tags date formatting, etc. The URL for the Formatting tags
is http://java.sun.com/jsp/jstl/fmt and prefix is fmt.
XML tags The XML tags provide flow control, transformation, etc. The URL for
tags is http://java.sun.com/jsp/jstl/xml and prefix is x.
SQL tags The JSTL SQL tags provide SQL support. The URL for the SQL tags
is http://java.sun.com/jsp/jstl/sql and prefix is sql.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Explain the use of cookies for tracking for tracking requests with a
program.
Session Tracking in JSP
Session Tracking :
HTTP is a "stateless" protocol which means each time a client retrieves a Web page, the
client opens a new connection to the Web server and the server does not keep any record of
previous client request.Session tracking is a mechanism that is used to maintain state about
a series of requests from the same user(requests originating from the same browser) across
some period of time. A session id is a unique token number assigned to a specific user for
the duration of that user's session.
Solution is, when a client makes a request it should introduce itself by providing unique
identifier every time.There are four ways to maintain session between web client and web
server.
Cookies :
Cookies mostly used for session tracking. Cookie is a key value pair of information, sent by the
server to the browser. This should be saved by the browser in its space in the client computer.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Whenever the browser sends a request to that server it sends the cookie along with it. Then the
server can identify the client using the cookie.
This is not an effective way because many time browser does not support a cookie or users can
opt to disable cookies using their browser preferences. In such case, the browser will not save
the cookie at client computer and session tracking fails.
jsp:useBean
jsp:include
jsp:setProperty
jsp:getProperty
jsp:forward
jsp:plugin
jsp:attribute
jsp:body
jsp:text
jsp:param
8.
jsp:attribute
jsp:output
MVC stands for Model View and Controller. It is a design pattern that separates
the business logic, presentation logic and data.
Controller acts as an interface between View and Model. Controller intercepts all
the incoming requests.
Model represents the state of the application i.e. data. It can also have business
logic.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
o register.html
o Register.java
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
o web.xml
register.html
In this page, we have getting input from the user using text fields and combobox.
The information entered by the user is forwarded to Register servlet, which is
responsible to store the data into the database.
1. <html>
2. <body>
3. <form action="servlet/Register" method="post">
4.
5. Name:<input type="text" name="userName"/><br/><br/>
6. Password:<input type="password" name="userPass"/><br/><br/>
7. Email Id:<input type="text" name="userEmail"/><br/><br/>
8. Country:
9. <select name="userCountry">
10. <option>India</option>
11. <option>Pakistan</option>
12. <option>other</option>
13. </select>
14.
15. <br/><br/>
16. <input type="submit" value="register"/>
17.
18. </form>
19. </body>
20. </html>
Register.java
This servlet class receives all the data entered by user and stores it into the
database. Here, we are performing the database logic. But you may separate it,
which will be better for the web application.
1. import java.io.*;
2. import java.sql.*;
3. import javax.servlet.ServletException;
4. import javax.servlet.http.*;
5.
6. public class Register extends HttpServlet {
7. public void doPost(HttpServletRequest request, HttpServletResponse response)
8. throws ServletException, IOException {
9.
10. response.setContentType("text/html");
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Apache Tomcat is a web server and servlet container that is used to serve Java
applications. Tomcat is an open source implementation of the Java Servlet and
JavaServer Pages technologies, released by the Apache Software Foundation. This
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
tutorial covers the basic installation and some configuration of the latest release of
Tomcat 8 on your Ubuntu 16.04 server.
Now that Java is installed, we can create a tomcat user, which will be used to run the
Tomcat service.
Next, create a new tomcat user. We’ll make this user a member of
the tomcat group, with a home directory of /opt/tomcat (where we will install
Tomcat), and with a shell of /bin/false (so nobody can log into the account):
Now that our tomcat user is set up, let’s download and install Tomcat.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
We will install Tomcat to the /opt/tomcat directory. Create the directory, then
extract the archive to it with these commands:
Next, we can set up the proper user permissions for our installation.
cd /opt/tomcat
Give the tomcat group ownership over the entire installation directory:
Next, give the tomcat group read access to the conf directory and all of its contents,
and execute access to the directory itself:
Make the tomcat user the owner of the webapps, work, temp,
and logs directories:
Now that the proper permissions are set up, we can create a systemd service file to
manage the Tomcat process.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
We want to be able to run Tomcat as a service, so we will set up systemd service file.
Tomcat needs to know where Java is installed. This path is commonly referred to as
“JAVA_HOME”. The easiest way to look up that location is by running this command:
Before we do that, we need to adjust the firewall to allow our requests to get to the
service. If you followed the prerequisites, you will have a ufw firewall enabled
currently.
Tomcat uses port 8080 to accept conventional requests. Allow traffic to that port by
typing:
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Your installation of Tomcat is complete! Your are now free to deploy your own Java
web applications!
11.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
As displayed in the above diagram, there are three states of a servlet: new, ready
and end. The servlet is in new state if servlet instance is created. After invoking
the init() method, Servlet comes in the ready state. In the ready state, servlet
performs all the tasks. When the web container invokes the destroy() method, it
shifts to the end state.
There are many advantages of JSP over the Servlet. They are as follows:
a) 1) Extension to Servlet
JSP technology is the extension to Servlet technology. We can use all the features
of the Servlet in JSP. In addition to, we can use implicit objects, predefined tags,
expression language and Custom tags in JSP, that makes JSP development easy.
b) 2) Easy to maintain
JSP can be easily managed because we can easily separate our business logic with
presentation logic. In Servlet technology, we mix our business logic with the
presentation logic.
If JSP page is modified, we don't need to recompile and redeploy the project. The
Servlet code needs to be updated and recompiled if we have to change the look
and feel of the application.
In JSP, we can use many tags such as action tags, JSTL, custom tags, etc. that
reduces the code. Moreover, we can use EL, implicit objects, etc.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
may also use IP address, 3306 is the port number and sonoo is the
database name. We may use any database, in such case, we need to
replace the sonoo with our database name.
3. Username: The default username for the mysql database is root.
4. Password: It is the password given by the user at the time of installing the
mysql database. In this example, we are going to use root as the password.
Let's first create a table in the mysql database, but before creating table, we need
to create database first.
1. import java.sql.*;
2. class MysqlCon{
3. public static void main(String args[]){
4. try{
5. Class.forName("com.mysql.jdbc.Driver");
6. Connection con=DriverManager.getConnection(
7. "jdbc:mysql://localhost:3306/sonoo","root","root");
8. //here sonoo is database name, root is username and password
9. Statement stmt=con.createStatement();
10. ResultSet rs=stmt.executeQuery("select * from emp");
11. while(rs.next())
12. System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
13. con.close();
14. }catch(Exception e){ System.out.println(e);}
15. }
16. }
(ii) List various JSP scripting components.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
B. JSP Comment
JSP Comment is used when you are creating a JSP page and want to put in comments
about what you are doing. JSP comments are only seen in the JSP page. These
comments are not included in servlet source code during translation phase, nor they
appear in the HTTP response. Syntax of JSP comment is as follows :
<%-- JSP comment --%>
(i) Demonstrate with suitable example for core and formatting tags
13.
in JSTL.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
The JSTL formatting tags are used for internationalized web sites to display and format
text, the time, the date and numbers. The syntax used for including JSTL formatting
library in your JSP is:
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Example
Let's see the simple example of < c:choose >, < c:when > < c:otherwise > tag:
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
(ii) Demonstrate with suitable example for SQL and XML tags in
JSTL.
JSTL SQL
The <sql:setDataSource> tag sets the data source configuration variable or saves the
data-source information in a scoped variable that can be used as input to the other JSTL
database actions.
Attribute
Attribute Description
Example
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
<html>
<head>
<title>JSTL sql:setDataSource Tag</title>
</head>
<body>
<sql:setDataSource var = "snapshot" driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost/TEST"
user = "user_id" password = "mypassword"/>
<sql:query dataSource = "${snapshot}" sql = "..." var = "result" />
</body>
</html>
JSTL XML
<x:parse> Tag
The <x:parse> tag is used for parse the XML data specified either in the tag body or an attribute. It is
used for parse the xml content and the result will stored inside specified variable.
EXAMPLE
1. <books>
2. <book>
3. <name>Three mistakes of my life</name>
4. <author>Chetan Bhagat</author>
5. <price>200</price>
6. </book>
7. <book>
8. <name>Tomorrow land</name>
9. <author>NUHA</author>
10. <price>2000</price>
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
11. </book>
12. </books>
index.jsp
(IN the same directory)
Output:
Books Info:
First Book title: Three mistakes of my life
Define HTML and JSP. Use the same and design a scientific calculator.
Calculator.jsp
14. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Calculator</title>
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
<style>
h1 {
font-family: Arial;
font-size: 14pt;
font-weight: normal;
}
td input {
font-family: Arial;
font-size: 10pt;
width: 30px;
}
input.double {
width: 60px;
}
input.doubleheight {
height: 48px;
}
input.display {
border: 1px solid black;
readonly: true;
width: 120px;
padding: 2px;
}
</style>
</head>
<body>
<h1>Calculator</h1>
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
PART – C
Q.No Questions
Design a HTML forms by embedding JSP code for submission of a resume to a job
portal website with appropriate database connectivity.
1.
Write a program that allows the user to select a favourite programming language and
3.
post the choice to the server. The response is a web page in which the user can click a
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
link to view a list of book recommendations. The cookies previously stored on the
client are read by the servlet and form a web page containing the book
recommendation. Use servlet cookies and HTML.
Develop a JSP program to display the grade of a student by accepting the marks of five
4.
subjects.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360