Вы находитесь на странице: 1из 19

1.

take stock of theory


1.1 main is already forgotten.
1.2 web tier part of jee.
1.3 there is a strucutre called war
structure ,w hich becuase we are
using ecclipse we are not conscious
about it.
1.1 html -- talk
1.2 jsp -- talk + read
1.3 servlet -- centralized processing
place
1.3.1 calling different business logic.
1.3.2 based on business logic status
deciding which page to show.
1.3.3 directing the response the page
decided on 1.3.2
1.4 business logic class.

business logic class functions typically


call the service layer functions.
many a times from this place we need
to share some message with either a
jsp .
to do this welcome to world of scope
variables (notice boards)
request scope variables
usually used
session scope variables.
this used if need is there.
we used request.setAttribute, think
about where you plan to read also.
Think about key and also value and
also data type of value.
in jsp we should know expression,
scriplet and some directive.

we have used jsp, in jsp we have used


lot of scriplets, expressions, usually
using scriplets in jsp is a sign that I
are am stupid.
why scriplets are bad.
typically in any website two skill sets
is required.
1. presentation skillset
2. business logic skillset.
expecting both to be in one person
typically we need to create the person
he wont be there in the world.

to write a scriplet what is most

important you got to know?


<h1 id="abc" class="def ghi"> hello
</h1>
<%
JAVA CODE
%>

to read notice board values, we are


using scriplets, thisis generally not
preferred what we prefer is to use
custom tags.
custom tags, what they do, they move

the functionality to a java class.

Java Beans.
this is an example how to confuse
people by keeping wrong names.
NJC == Pure Old Java Object.
java bean a java class which adhers to
the naming convnetions ie if variable
is i, setter has to b setI and getI

in java there is a class called Class.


without this nothing works in java.
we created a class called Emp. to use
this class, a Class object is created for
Emp , only then it can be used.
1. jsp using scriplet is a bad idea, it
causees problems when delegation of
job is involved.
2. java bean
3. reflection.
3.1 class called Class.
3.2 to use any class, a Class class
object has to be created for that class.
example , we are creating calling a
static function on a class called Y. ok A
Class class object has to be created
for Y.
we are creating 100 objects of Integer.

ok one Class class object has to be


created for Integer.

usually when we create the object we


know the naem of the class at compile
time, sometimes we will have the
need to create an object whose
classname is known at runtime.
creating objects whose classname is
known at runtime would make sense
only if we know power of interfaces.

if there is a need to create a Class


class object for a particualr.
1. you know the classname.
"a.b.c.Resource"
Class c = Class.forName("give me the
classname");
2. you got a object whatever handle.
Object o = ?;
Class c = o.getClass();
Class o = Freak.class
is another way of getting the Class

class object in case we know the


classname during coding time.
story before lunch break is as follows.
1. custom tags should be used in jsp
so that delegation of job happens.
page author and business logic people
need not be teh same person.
2. by using a cocnept like java bean
setters and getters are called
automatically becuase we are
adhering to naming conventions.
3. getters was called, setters were
getting called when we used action in
jsp
<jsp:setproperty ...>, becuase it was
using reflection.
4. reflection, we got started with Class

class.
5. sometimes there is a need to create
an object whose class name is known
at runtime.
6. the way we do it.
get the classname at runtime in a
string.
get the Class class object associated
with that class.
do a newinstance.
this is ok provided we are using an
interface. else it would not make
logical sense.
7. for RTTI we can also use getClass
function which returns you the Class
class object associated with the class
to whcih the object belongs.
Object o ="Hello"

here object is of type String.


we want to get Class class object
associated with String.
Class c = o.getClass();

we want to remove scriplets from our


code.
we are going to use a custom tag
library.
custom tag library name is JSTL.
Java Standard Tag Library.

custom tag library = you some class


files + some tld files + some
documentation hopefully.
custom tag library = jar files + some
tld files + some documentation
hopefully.
how to use this in web project.
1. copy the jar files into the lib folder
o your project.
2. copy the tld files into the web-inf
folder .
3. have a ready made jsp which
proves custom tag is working.
what does jstl custom tag do, it can do
lot of things.
1. ability to read different notice

boards.
2. ability to loop thru datastructures.
3. in case it is empty, it will
automatically it will not print, without
we telling it what to do.
4. concept of java bean is required to
understand this.

during coding intelligence is not there


ok, but patience is not there,
disgusting.
how to use custom tag in the project.
1. include the custom related jar files
in your lib of web-inf.

2. put the tld file in web-inf folder.


3. in the jsp use the taglib directive
and use the necessary custom tag.

2. take stock of practicals.


3. Reflection, java beans
4. Custom tags.
5. XML programatic apis
6. warm up on struts 2.x

Вам также может понравиться