0% found this document useful (0 votes)
52 views8 pages

Interface Summary

The document discusses the javax.servlet.http package which contains classes and interfaces that define contracts between servlets and servlet containers for HTTP requests and responses. It provides an overview of key interfaces like HttpServletRequest and HttpServletResponse and their methods. It also discusses how to develop a JSP page that uses a Java bean in the application scope by creating a Counter bean class, instantiating it in the JSP, and accessing its properties.

Uploaded by

Sandeep Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views8 pages

Interface Summary

The document discusses the javax.servlet.http package which contains classes and interfaces that define contracts between servlets and servlet containers for HTTP requests and responses. It provides an overview of key interfaces like HttpServletRequest and HttpServletResponse and their methods. It also discusses how to develop a JSP page that uses a Java bean in the application scope by creating a Counter bean class, instantiating it in the JSP, and accessing its properties.

Uploaded by

Sandeep Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1. Explain the functionality of javax.servlet.

http package by discussing about the methods and


interfaces of this package?

The javax.servlet.http package contains a number of classes and interfaces that describe
and define the contracts between a servlet class running under the HTTP protocol and the
runtime environment provided for an instance of such a class by a conforming servlet
container.

        

Interface Summary
Extends the ServletRequest interface to provide request
HttpServletRequest
information for HTTP servlets.
Extends the ServletResponse interface to provide HTTP-
HttpServletResponse
specific functionality in sending a response.
Provides a way to identify a user across more than one page
HttpSession request or visit to a Web site and to store information about
that user.
Objects that are bound to a session may listen to container
HttpSessionActivationListene
events notifying them that sessions will be passivated and that
r
session will be activated.
Interface for receiving notification events about HttpSession
HttpSessionAttributeListener
attribute changes.
Causes an object to be notified when it is bound to or unbound
HttpSessionBindingListener
from a session.
Deprecated. As of Java(tm) Servlet API 2.1 for security
HttpSessionContext
reasons, with no replacement.
Interface for receiving notification events about HttpSession
HttpSessionListener
lifecycle changes.
This class represents a part or form item that was received
Part
within a multipart/form-data POST request.
 
METHODS:

addCookie(Cookie) - Method in interface javax.servlet.http.HttpServletResponse


Adds the specified cookie to the response.

addCookie(Cookie) - Method in class


javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to call addCookie(Cookie cookie) on the
wrapped response object.

addDataModelListener(DataModelListener) - Method in class


javax.faces.model.DataModel
Add a new DataModelListener to the set interested in notifications from
this DataModel.

addDateHeader(String, long) - Method in interface


javax.servlet.http.HttpServletResponse
Adds a response header with the given name and date-value.

addDateHeader(String, long) - Method in class


javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to call addDateHeader(String name, long
date) on the wrapped response object.
2.a.Give a note on fixed-template data?

Fixed Template Data

 These are the parts of a JSP page that are used verbatim in the response.

Or in input to JSP actions see later.

 In simple cases this data will take the form of plain HTML.

 This text can be written anywhere in the JSP file. It is copied unchanged, in lexical order,
to the output stream of a response

b. Describe model-view-controller setup?

Model-View-Controller (MVC) is a classic design pattern often used by applications that need
the ability to maintain multiple views of the same data. The MVC pattern hinges on a clean
separation of objects into one of three categories — models for maintaining data, views for
displaying all or a portion of the data, and controllers for handling events that affect the model
or view(s).Because of this separation, multiple views and controllers can interface with the same
model. Even new types of views and controllers that never existed before can interface with a
model without forcing a change in the model design.

The Model-View-Controller (MVC) pattern separates the modeling of the domain, the


presentation, and the actions based on user input into three separate classes
[Burbeck92]:

 Model. The model manages the behavior and data of the application domain,
responds to requests for information about its state (usually from the view), and
responds to instructions to change state (usually from the controller).

 View. The view manages the display of information.

 Controller. The controller interprets the mouse and keyboard inputs from the user,
informing the model and/or the view to change as appropriate.

Figure 1 depicts the structural relationship between the three objects .


Figure 1: MVC class structure

It is important to note that both the view and the controller depend on the model. However, the model depends on
neither the view nor the controller. This is one the key benefits of the separation. This separation allows the model to
be built and tested independent of the visual presentation. The separation between view and controller is secondary
in many rich-client applications, and, in fact, many user interface frameworks implement the roles as one object. In
Web applications, on the other hand, the separation between view (the browser) and controller (the server-side
components handling the HTTP request) is very well defined.

Model-View-Controller  is a fundamental design pattern for the separation of user interface logic from business logic.
Unfortunately, the popularity of the pattern has resulted in a number of faulty descriptions. In particular, the term
"controller" has been used to mean different things in different contexts. Fortunately, the advent of Web applications
has helped resolve some of the ambiguity because the separation between the view and the controller is so apparent

c.write about javax.servlet.jsptagext package?

Package javax.servlet.jsp.tagext Description


Classes and interfaces for the definition of JavaServer Pages Tag Libraries.

Custom actions can be used by JSP authors and authoring tools to simplify writing
JSP pages. A custom action can be either an empty or a non-empty action.

An empty tag has no body. There are two equivalent syntaxes, one with separate start
and end tags, and one where the start and end tags are combined. The two following
examples are identical:
<x:foo att="myObject"></foo>
<x:foo att="myObject"/>

A non-empty tag has a start tag, a body, and an end tag. A prototypical example is of
the form:
<x:foo att="myObject" >
BODY
</x:foo/>
The JavaServer Pages(tm) (JSP) specification provides a portable mechanism for the
description of tag libraries.

A JSP tag library contains

 A Tag Library Descriptor


 A number of Tag Files or Tag handler classes defining request-time behavior
 Additional classes and resources used at runtime
 Possibly some additional classes to provide extra translation information

         Description

Interface Summary
The BodyTag interface extends IterationTag by defining additional methods that let
BodyTag
a tag handler manipulate the content of evaluating its body.

For a tag to declare that it accepts dynamic attributes, it must implement this
DynamicAttributes
interface.

The IterationTag interface extends Tag by defining one additional method that
IterationTag
controls the reevaluation of its body.

This interface indicates to the container that a tag handler wishes to be provided
JspIdConsumer
with a compiler generated ID.

JspTag Serves as a base class for Tag and SimpleTag.

SimpleTag Interface for defining Simple Tag Handlers.

Tag The interface of a classic tag handler that does not want to manipulate its body.

The auxiliary interface of a Tag, IterationTag or BodyTag tag handler that wants
TryCatchFinally
additional hooks for managing resources.

 
3.a. Develop a jsp with a bean in the application scope?

Using Java Beans in JSP


Java Bean is a reusable component. We can use java beans in different programming applications or
environments.
Example Program
Use a java bean that acts as a counter. It has a single integer property. The variable 'count' holds the
current number of times the bean property has been accessed. It also contains appropriate methods
for getting and setting this property.
Counter.java
package test
public class Counter { private int count; //declares a new property value..
public counter()
{ count=0; //initializes the property value.
}
public int getCount() //accessor method
{ count++;
return (this.count);
}
public void setCount(int c) //mutator method
{ this.count=c;
}
}
BeanCounter.jsp
<html>
<body>
<jsp:useBean id="counter" scope ="session" class="Counter"/>
//Instantiate a javaBean
<jsp:setProperty name="counter" value=10 property="count"/>
//write the current value of property count
//will call mutator method. (request the parameter count using setProperty
Count from jsp:getproperty:
<jsp:getProperty name="counter" property="count"/>
//Count from jsp:getProperty:
</body>
</html>
Step1: create a folder myjsp inside the root folder of Apache called webapps
Step2: create a Counter.java file in a package called test inside webapps\myjsp folder of Apache.
Step 3: compile the Counter.java file and put the Counter.class file in the webapps\myjsp\WEB-
INF\classes\test

Step4: Create the JSP called BeanCounter.jsp that uses Counter bean and place it in
webapps\myjsp\test folder

Step 5: Run the BeanCounter.jsp using the URL:http://localhost:8080/myjsp/test/BeanCounter.jsp


The output is

Count from jsp:getproperty:11


b. What is scriplet? Write about scriplet elements?

we can access java beans with scriplets.

ACCESSING JAVABEANS THROUGH SCRIPLETS


The scriplet element can be used to add a whole block of code to a page, including variable
declarations. The code block must be enclosed by a scriptlet start-identifier, <% and an end identifier,
%>.
//Example 2
//StringBean.java
package tbean;
/** A simple bean that has a single String property called message */
public class StringBean
{private String message = "No message specified";
public String getMessage()
{
return(message);
}
public void setMessage(String message)
{
this.message = message;
}
}
//StringBean.jsp
<HTML>
<HEAD>
<TITLE>Using JavaBeans with JSP</TITLE>
</HEAD>
<BODY>
<h1>Using JavaBeans with JSP</h1>
<jsp:useBean id="stringBean" class="tbean.StringBean" />
<OL>

<LI>Initial value (getProperty)

<I><jsp:getProperty name="stringBean" property="message" /></I>


<LI>Initial value (JSP expression):
<I><%= stringBean.getMessage() %></I> /*Using Scriptlets*/
<LI><jsp:setProperty name="stringBean" property="message"value="Welcome to JSP
world" />
Value after setting property with setProperty:
<I><jsp:getProperty name="stringBean" property="message" /></I>
<LI><% stringBean.setMessage("Use javaBean in JSP"); %> /* Using Scriptlets*/
Value after setting property with scriptlet:
<I><%= stringBean.getMessage() %></I> /* Using Scriptlets*/
</OL>
</BODY>
</HTML>
//output

You might also like