Tuesday, August 31, 2010

Photographers Right movement to Click..!

Some People Click Their Cameras At Precisely The Right Moment!!!!!!













Live every day with enjoyment - we don't know what tomorrow will give us.






A one in a billion shot.

Can you imagine being in position to get one of these photos? A one in a billion shot.

Enjoy!

Best Deals only
....














Potential Gold Mines found in South India

Potential Gold Mines found in South India


Marry a malayali girl and see how much gold you can get...









For those who are already married.... Sorry folks....







Monday, August 30, 2010

What is the difference between HttpSession mySession=request.getSession(true) and HttpSession mySession=request.getSession()


What is the difference between HttpSession mySession=request.getSession(true) and HttpSession mySession=request.getSession().?

Answer
:

request.getSession() will return the current session and if one does not exist, a new session will be cretaed.

request.getSession(true) will return the current session if one exists, if one doesn't exits a new one will be created.

So there is actually no difference between the two methods HOWEVER, if you use request.getSession(false), it will return the current session if one exists and if one DOES NOT exist a new one will NOT be cretaed.

Types of Joins in Oracle with Examples

Oracle Joins

9i Joins:
Supports ANSI/ISO standard Sql 1999 syntax
Made easy for Appln s/w tools to understand Sql Queries

1. Natural Join
2. Join with Using
3. Join with ON
4. Inner Join
5. Left outer join
6. Right outer join
*7. Full outer join
8. Cross join

1. > select empno,ename,sal,job,deptno,dname,loc
from emp natural join dept;

2. > select empno,ename,sal,job,deptno,dname,loc
from emp join dept using(deptno);

3. > select e.empno, e.ename, e.sal, e.job, e.deptno, d.dname, d.loc from emp e Join dept d
on(e.deptno = d.deptno) ;

4. > select e.empno, e.ename, e.sal, e.job, e.deptno,d.dname, d.loc from emp e Inner Join dept d
on(e.deptno = d.deptno) ;

5. > select e.empno, e.ename, e.sal, e.job, e.deptno,d.dname, d.loc from emp e left outer join dept d on(e.deptno = d.deptno) ;

6. > select e.empno, e.ename, e.sal, e.job, e.deptno,d.dname, d.loc from emp e right outer join dept d on(e.deptno = d.deptno) ;

* 7. > select e.empno, e.ename, e.sal, e.job, e.deptno,d.dname, d.loc from emp e full outer join dept d on(e.deptno = d.deptno) ;

** left outer join union right outer join = full outer join

8. > select empno,ename,sal,job,deptno,dname,loc from emp cross join dept;

Sunday, August 29, 2010

Oracle 8.0 Features

8.0 Features



Returning into clause:
Used to return the values thru " DML" stmts.
Used with update and delete stmts.
Ex:
>var a varchar2(20)
>var b number
>update emp set sal = sal + 3000 where empno = 7900
returning ename,sal into :a,:b;
>print a b

>delete from emp where empno = 7902
returning ename,sal into :a,:b;
>print a b
----------------------------------------------------------------------------
* Bulk Collect:
Used to return bulk data into pl/sql variables.
Variables must be of pl/sql table type only.
Improves performance while retrieving data.
Used with select, update, delete, Fetch stmts.

select ename,sal into a,b from emp where empno = &ecode;
ecode : 101

>declare
type names is table of emp.ename%type index by binary_integer;
type pays is table of emp.sal%type index by binary_integer;
n names; p pays;
begin
-- retrieving all employees in 1 transaction
select ename,sal bulk collect into n,p from emp;
-- printing table contents
dbms_output.put_line('EMPLOY DETAILS ARE :');
for i in 1 .. n.count loop
dbms_output.put_line(n(i)||' '||p(i));
end loop;
end;

* update emp set sal = sal + 3000 where deptno = 30
returning ename,sal bulk collect into n,p;

* delete from emp where job = 'CLERK'
returning ename,sal bulk collect into n,p;
----------------------------------------------------------------------------
Using in Fetch stmt :
declare
type names is table of emp.ename%type index by binary_integer;
type pays is table of emp.sal%type index by binary_integer;
n names; p pays;
cursor c1 is select ename,sal from emp;
begin
open c1;
fetch c1 bulk collect into n,p;
-- printing table contents
for i in 1 .. n.count loop
dbms_output.put_line(n(i)||' '||p(i));
end loop;
end;
----------------------------------------------------------------------------
Dynamic SQL:
Supports to execute " DDL" stmts in Pl/sql block.
syntax: execute immediate(' DDL stmt ');

>begin
execute immediate(' create table employ1
(ecode number(4), ename varchar2(20),sal number(10))');
end;

Note: Table cannot be manipulated in same pl/sql block

begin
execute immediate('drop table employ1');
end;
----------------------------------------------------------------------------

Introduce yourself in interviews

The most frequently asked question is tell me about your self briefly.The interview starts with this question only.Let us read some questions like...



1)Tell me about yourself?

A)Well,As you know Iam Hemanath Chowdary from Damlacheruvu which is little near to Chittoor in the part of Andhra Pradesh. I born and brought up in Andhrapradesh itself.

My Education Qualifiacation are I did my schooling in Games high school at tirupathi. After my schooling, I finished my graduation of Bsc Chemistry from S.V.arts college in 2006 that is affiliated to S.V. University at Tirupathi. After finishing my graduation, I have done my MCA from J N T University in2009.

Then I got selected in Solidus Multitech pvt ltd in bangalore and having around 2 yrs exp in Microsoft .NET technologies such as C#.net,Asp.net,Ado.net and other tool such as Ms sql server,Flat Text file,photoshop and dreamweaver.

Note:
• Here you should specify your experience on your projects...
• My career objective is Looking forward for a better carrer in Organization
• My strengths are dedications....willingness to walk an extra mile to achieve my career.
• Iam very eager to learn new technologies
• My weakness are.....

About my family background:
• My father is a retired headmaster and mother is a homemaker and i have 4 sisters and don't have brothers.
About my hoppies:
• singing song,playing cricket and watching TV

2)If we hire you, and then another company will offer you more money - what will you do?
A) Sir,money is not the matter.I prefer a company which gives me a oppurtunity to expose my ideas in a clear manner.
3)Why you are looking for change ?


A)i am looking for technical and economical growth, and wantto work in such environment where i can use my skill,innovative ideas and also improve my knowledge and skill.

4) how much salary you expected?

A)IT DEPENDS ON NOT ONLY COMPANY STANDARDS BUT ALSO ASPERINDIVIDUAL'S EXPERIENCE,PERFORMANCE AND CAPABILITY IN THE
PREVIOUS JOB AND MARKET CONDITION.

5) What does success mean to you?

A)For me success is not a destination of a achievement.It is a continous journey.
6) what are your strengths ?

A) My strengths are optimistic,self learner,team worker.i m altruist also

7) Tell me about your dream job.

A)The job that doesn't appear in my dream while i sleep.

8) What do you expect of others in a team environment?

A)Sharing knowledge & valuing the others opinion.

Thursday, August 26, 2010

Clash of the Animal Titans

An incredible clash of Titans shows how a pregnant warthog desperately tries to defend herself - and her unborn baby - as a wild leopard savagely launches a stealth attack.

The explosive battle was caught on camera by British amateur photographer Mike Bailey as he holidayed in the remote Kwando River area of northern Botswana, Africa.

The spectacular dual between the huge spotted cat and the stouter tusked pig amazingly lasted over 10 minutes as the leopard tried to get the better of its prey.










Tuesday, August 24, 2010

Heart Attacks And Drinking Warm Water

A very good article which takes two minutes to read. I'm sending this to persons I care about.......I hope you do too!!!
Heart Attacks And Drinking Warm Water




This is a very good article. Not only about the warm water after your meal, but about Heart Attacks . The Chinese and Japanese drink hot tea with their meals, not cold water, maybe it is time we adopt their drinking habit while eating.





For those who like to drink cold water, this article is applicable to you. It is feels nice to have a cup of cold drink after a meal. However, the cold water will solidify the oily stuff that you have just consumed. It will slow down the digestion. Once this 'sludge' reacts with the acid, it will break down and be absorbed by the intestine faster than the solid food. It will line the intestine. Very soon, this will turn into fats and lead to cancer . It is best to drink hot soup or warm water after a meal.
French fries and Burgers are the biggest enemy of heart health.
A coke after that gives more power to this demon.
Avoid them for your Heart's Health

Common Symptoms Of Heart Attack...
A serious note about heart attacks - You should know that not every heart attack symptom is going to be the left arm hurting .
Be aware of intense pain in the jaw line .

You may never have the first chest pain during the course of a heart attack.
Nausea and intense sweating are also common symptoms.
60% of people who have a heart attack while they are asleep do not wake up. Pain in the jaw can wake you from a sound sleep. Let's be careful and be aware. The more we know, the better chance we could survive.


A cardiologist says if everyone who reads this message sends it to 10 people, you can be sure that we'll save at least one life. Read this & Send to a friend. It could save a life... So, please be a true friend and send this article to all your friends you care about.



I JUST DID




Thursday, August 12, 2010

Java™ Servlet Specification.pdf download

Java™ Servlet Specification
Version 2.4

Please send technical comments to: servletapi-feedback@eng.sun.com
Please send business comments to: danny.coward@sun.com
Public Draft June 24th 2002
Danny Coward (danny.coward@sun.com)
Yutaka Yoshida (yutaka.yoshida@sun.com)


Java™ Servlet Specification Version 2.4 . . . . . . . . . . . . . . . .i
Changes since version 2.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Changes in this document since version 2.3 . . . . . . . . . . . . . . . . . xiii
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Additional Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Who Should Read This Specification . . . . . . . . . . . . . . . . . . . . . . xvi
API Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Other Java™ Platform Specifications . . . . . . . . . . . . . . . . . . . . . . xvi
Other Important References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Providing Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
SRV.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
SRV.1.1 What is a Servlet? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
SRV.1.2 What is a Servlet Container? . . . . . . . . . . . . . . . . . . . . . . 19
SRV.1.3 An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
SRV.1.4 Comparing Servlets with Other Technologies . . . . . . . . 20
SRV.1.5 Relationship to Java 2, Platform Enterprise Edition . . . . 21
SRV.2 The Servlet Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
SRV.2.1 Request Handling Methods . . . . . . . . . . . . . . . . . . . . . . . 23
SRV.2.1.1 HTTP Specific Request Handling Methods . . . . 23
SRV.2.1.2 Additional Methods . . . . . . . . . . . . . . . . . . . . . . 24
SRV.2.1.3 Conditional GET Support . . . . . . . . . . . . . . . . . . 24
CONTENTS vi
SRV.2.2 Number of Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
SRV.2.2.1 Note About The Single Thread Model . . . . . . . . 25
SRV.2.3 Servlet Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
SRV.2.3.1 Loading and Instantiation . . . . . . . . . . . . . . . . . . 25
SRV.2.3.2 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
SRV.2.3.3 Request Handling . . . . . . . . . . . . . . . . . . . . . . . . 26
SRV.2.3.4 End of Service . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
SRV.3 Servlet Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
SRV.3.1 Introduction to the ServletContext Interface . . . . . . . . . . 29
SRV.3.2 Scope of a ServletContext Interface . . . . . . . . . . . . . . . . 29
SRV.3.3 Initialization Parameters . . . . . . . . . . . . . . . . . . . . . . . . . 30
SRV.3.4 Context Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
SRV.3.4.1 Context Attributes in a Distributed Container . . 30
SRV.3.5 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
SRV.3.6 Multiple Hosts and Servlet Contexts . . . . . . . . . . . . . . . 31
SRV.3.7 Reloading Considerations . . . . . . . . . . . . . . . . . . . . . . . . 31
SRV.3.7.1 Temporary Working Directories . . . . . . . . . . . . . 32
SRV.4 The Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
SRV.4.1 HTTP Protocol Parameters . . . . . . . . . . . . . . . . . . . . . . . 33
SRV.4.1.1 When Parameters Are Available . . . . . . . . . . . . . 34
SRV.4.2 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
SRV.4.3 Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
SRV.4.4 Request Path Elements . . . . . . . . . . . . . . . . . . . . . . . . . . 35
SRV.4.5 Path Translation Methods . . . . . . . . . . . . . . . . . . . . . . . . 37
SRV.4.6 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
SRV.4.7 SSL Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
SRV.4.8 Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
SRV.4.9 Request data encoding . . . . . . . . . . . . . . . . . . . . . . . . . . 39
SRV.4.10 Lifetime of the Request Object . . . . . . . . . . . . . . . . . . . . 39
SRV.5 The Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
SRV.5.1 Buffering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
SRV.5.2 Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
SRV.5.3 Convenience Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
CONTENTS vii
SRV.5.4 Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
SRV.5.5 Closure of Response Object . . . . . . . . . . . . . . . . . . . . . . 44
SRV.5.6 Lifetime of the Response Object . . . . . . . . . . . . . . . . . . . 45
SRV.6 Filtering. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
SRV.6.1 What is a filter? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
SRV.6.1.1 Examples of Filtering Components . . . . . . . . . . 48
SRV.6.2 Main Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
SRV.6.2.1 Filter Lifecycle . . . . . . . . . . . . . . . . . . . . . . . . . . 48
SRV.6.2.2 Wrapping Requests and Responses . . . . . . . . . . 50
SRV.6.2.3 Filter Environment . . . . . . . . . . . . . . . . . . . . . . . 50
SRV.6.2.4 Configuration of Filters in a Web Application . . 51
SRV.6.2.5 Filters and the RequestDispatcher . . . . . . . . . . . 52
SRV.7 Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
SRV.7.1 Session Tracking Mechanisms . . . . . . . . . . . . . . . . . . . . 55
SRV.7.1.1 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
SRV.7.1.2 SSL Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
SRV.7.1.3 URL Rewriting . . . . . . . . . . . . . . . . . . . . . . . . . . 56
SRV.7.1.4 Session Integrity . . . . . . . . . . . . . . . . . . . . . . . . . 56
SRV.7.2 Creating a Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
SRV.7.3 Session Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
SRV.7.4 Binding Attributes into a Session . . . . . . . . . . . . . . . . . . 57
SRV.7.5 Session Timeouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
SRV.7.6 Last Accessed Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
SRV.7.7 Important Session Semantics . . . . . . . . . . . . . . . . . . . . . 58
J2EE.7.7.1 Threading Issues . . . . . . . . . . . . . . . . . . . . . . . . . 58
SRV.7.7.2 Distributed Environments . . . . . . . . . . . . . . . . . . 58
SRV.7.7.3 Client Semantics . . . . . . . . . . . . . . . . . . . . . . . . . 59
SRV.8 Dispatching Requests. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
SRV.8.1 Obtaining a RequestDispatcher . . . . . . . . . . . . . . . . . . . . 61
SRV.8.1.1 Query Strings in Request Dispatcher Paths . . . . 62
SRV.8.2 Using a Request Dispatcher . . . . . . . . . . . . . . . . . . . . . . 62
SRV.8.3 The Include Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
SRV.8.3.1 Included Request Parameters . . . . . . . . . . . . . . . 63
SRV.8.4 The Forward Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
CONTENTS viii
SRV.8.4.1 Query String . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
SRV.8.5 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
SRV.9 Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
SRV.9.1 Web Applications Within Web Servers . . . . . . . . . . . . . 65
SRV.9.2 Relationship to ServletContext . . . . . . . . . . . . . . . . . . . 65
SRV.9.3 Elements of a Web Application . . . . . . . . . . . . . . . . . . . 66
SRV.9.4 Deployment Hierarchies . . . . . . . . . . . . . . . . . . . . . . . . 66
SRV.9.5 Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
SRV.9.5.1 Example of Application Directory Structure . . . 67
SRV.9.6 Web Application Archive File . . . . . . . . . . . . . . . . . . . . 68
SRV.9.7 Web Application Deployment Descriptor . . . . . . . . . . . 68
SRV.9.7.1 Dependencies On Extensions . . . . . . . . . . . . . . . 68
SRV.9.7.2 Web Application Classloader . . . . . . . . . . . . . . 69
SRV.9.8 Replacing a Web Application . . . . . . . . . . . . . . . . . . . . 69
SRV.9.9 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
SRV.9.9.1 Request Attributes . . . . . . . . . . . . . . . . . . . . . . . 70
SRV.9.9.2 Error Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
SRV.9.10 Welcome Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
SRV.9.11 Web Application Environment . . . . . . . . . . . . . . . . . . . 73
SRV.10 Application Lifecycle Events . . . . . . . . . . . . . . . . . . . . . . . 75
SRV.10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
SRV.10.2 Event Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
SRV.10.2.1 Event Types and Listener Interfaces . . . . . . . . . 75
SRV.10.2.2 An Example of Listener Use . . . . . . . . . . . . . . . 77
SRV.10.3 Listener Class Configuration . . . . . . . . . . . . . . . . . . . . . 77
SRV.10.3.1 Provision of Listener Classes . . . . . . . . . . . . . . . 77
SRV.10.3.2 Deployment Declarations . . . . . . . . . . . . . . . . . . 77
SRV.10.3.3 Listener Registration . . . . . . . . . . . . . . . . . . . . . 77
SRV.10.3.4 Notifications At Shutdown . . . . . . . . . . . . . . . . 78
SRV.10.4 Deployment Descriptor Example . . . . . . . . . . . . . . . . . . 78
SRV.10.5 Listener Instances and Threading . . . . . . . . . . . . . . . . . 78
SRV.10.6 Listener Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
SRV.10.7 Distributed Containers . . . . . . . . . . . . . . . . . . . . . . . . . . 79
CONTENTS ix
SRV.10.8 Session Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
SRV.11 Mapping Requests to Servlets . . . . . . . . . . . . . . . . . . . . . . 81
SRV.11.1 Use of URL Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
SRV.11.2 Specification of Mappings . . . . . . . . . . . . . . . . . . . . . . . 82
SRV.11.2.1 Implicit Mappings . . . . . . . . . . . . . . . . . . . . . . . 82
SRV.11.2.2 Example Mapping Set . . . . . . . . . . . . . . . . . . . . 83
SRV.12 Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
SRV.12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
SRV.12.2 Declarative Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
SRV.12.3 Programmatic Security . . . . . . . . . . . . . . . . . . . . . . . . . . 86
SRV.12.4 Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
SRV.12.5 Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
SRV.12.5.1 HTTP Basic Authentication . . . . . . . . . . . . . . . . 88
SRV.12.5.2 HTTP Digest Authentication . . . . . . . . . . . . . . . 89
SRV.12.5.3 Form Based Authentication . . . . . . . . . . . . . . . . 89
SRV.12.5.4 HTTPS Client Authentication . . . . . . . . . . . . . . 91
SRV.12.6 Server Tracking of Authentication Information . . . . . . . 91
SRV.12.7 Propagation of Security Identity in EJBTM Calls . . . . . 91
SRV.12.8 Specifying Security Constraints . . . . . . . . . . . . . . . . . . . 92
SRV.12.9 Default Policies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
SRV.12.10Login and Logout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
SRV.12.10.1 Login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
SRV.12.10.2 Logout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
SRV.13 Deployment Descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
SRV.13.1 Extensibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
SRV.13.1.1 Example of Extensibility: ACME servlets . . . . . 96
SRV.13.2 Deployment Descriptor Elements . . . . . . . . . . . . . . . . . 98
SRV.13.3 Rules for Processing the Deployment Descriptor . . . . . 99
SRV.13.4 Deployment Descriptor . . . . . . . . . . . . . . . . . . . . . . . . . 99
SRV.13.5 Picture of the structure of a Deployment Descriptor . . 132
SRV.13.6 DTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
SRV.13.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
SRV.13.7.1 A Basic Example . . . . . . . . . . . . . . . . . . . . . . . 135
SRV.13.7.2 An Example of Security . . . . . . . . . . . . . . . . . . 136
CONTENTS x
SRV.14 javax.servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
SRV.14.1 Generic Servlet Interfaces and Classes . . . . . . . . . . . . . 139
SRV.14.2 The javax.servlet package . . . . . . . . . . . . . . . . . . . . . . . 139
SRV.14.2.1 Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
SRV.14.2.2 FilterChain . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
SRV.14.2.3 FilterConfig . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
SRV.14.2.4 GenericServlet . . . . . . . . . . . . . . . . . . . . . . . . . . 145
SRV.14.2.5 RequestDispatcher . . . . . . . . . . . . . . . . . . . . . . 149
SRV.14.2.6 Servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
SRV.14.2.7 ServletConfig . . . . . . . . . . . . . . . . . . . . . . . . . . 153
SRV.14.2.8 ServletContext . . . . . . . . . . . . . . . . . . . . . . . . . . 154
SRV.14.2.9 ServletContextAttributeEvent . . . . . . . . . . . . . . 163
SRV.14.2.10 ServletContextAttributeListener . . . . . . . . . . . 164
SRV.14.2.11 ServletContextEvent . . . . . . . . . . . . . . . . . . . . 164
SRV.14.2.12 ServletContextListener . . . . . . . . . . . . . . . . . . . 165
SRV.14.2.13 ServletException . . . . . . . . . . . . . . . . . . . . . . . 166
SRV.14.2.14 ServletInputStream . . . . . . . . . . . . . . . . . . . . . . 167
SRV.14.2.15 ServletOutputStream . . . . . . . . . . . . . . . . . . . . 168
SRV.14.2.16 ServletRequest . . . . . . . . . . . . . . . . . . . . . . . . . 172
SRV.14.2.17 ServletRequestAttributeEvent . . . . . . . . . . . . . 179
SRV.14.2.18 ServletRequestAttributeListener . . . . . . . . . . . 180
SRV.14.2.19 ServletRequestEvent . . . . . . . . . . . . . . . . . . . . 181
SRV.14.2.20 ServletRequestListener . . . . . . . . . . . . . . . . . . 182
SRV.14.2.21 ServletRequestWrapper . . . . . . . . . . . . . . . . . . 182
SRV.14.2.22 ServletResponse . . . . . . . . . . . . . . . . . . . . . . . . 187
SRV.14.2.23 ServletResponseWrapper . . . . . . . . . . . . . . . . . 192
SRV.14.2.24 SingleThreadModel . . . . . . . . . . . . . . . . . . . . . 196
SRV.14.2.25 UnavailableException . . . . . . . . . . . . . . . . . . . 196
SRV.15 javax.servlet.http . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
SRV.15.1 Servlets Using HTTP Protocol . . . . . . . . . . . . . . . . . . . 199
SRV.15.1.1 Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
SRV.15.1.2 HttpServlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
SRV.15.1.3 HttpServletRequest . . . . . . . . . . . . . . . . . . . . . . 214
SRV.15.1.4 HttpServletRequestWrapper . . . . . . . . . . . . . . . 221
SRV.15.1.5 HttpServletResponse . . . . . . . . . . . . . . . . . . . . . 226
SRV.15.1.6 HttpServletResponseWrapper . . . . . . . . . . . . . . 237
SRV.15.1.7 HttpSession . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
CONTENTS xi
SRV.15.1.8 HttpSessionActivationListener . . . . . . . . . . . . . 246
SRV.15.1.9 HttpSessionAttributeListener . . . . . . . . . . . . . . 247
SRV.15.1.10 HttpSessionBindingEvent . . . . . . . . . . . . . . . . 248
SRV.15.1.11 HttpSessionBindingListener . . . . . . . . . . . . . . 249
SRV.15.1.12 HttpSessionContext . . . . . . . . . . . . . . . . . . . . . 250
SRV.15.1.13 HttpSessionEvent . . . . . . . . . . . . . . . . . . . . . . . 250
SRV.15.1.14 HttpSessionListener . . . . . . . . . . . . . . . . . . . . . 251
SRV.15.1.15 HttpUtils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
SRV.A Deployment Descriptor Version 2.2 . . . . . . . . . . . . . . . . 255
SRV.A.1 Deployment Descriptor DOCTYPE . . . . . . . . . . . . . . . 255
SRV.A.2 DTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
SRV.A.1 Deployment Descriptor DOCTYPE . . . . . . . . . . . . . . . 269
SRV.A.2 DTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
SRV.B Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

Jakarta Struts 1.1 pdf by Atlanta Java Users Group (download)

Jakarta Struts 1.1
Ready for Prime Time
Atlanta Java Users Group (AJUG)
August 20 2002
Chuck Cavaness



Presentation Goals

��Introduce Struts from 5,280 ft
��Introduce the Struts 1.1 features
��Highlight the steps for developing a Struts application ��Subliminallyemphasize the importance and benefit of using a framework like Struts

Monday, August 9, 2010

How to do JUnit Testing Example

JUnit – Testing
JUnit is a simple Java testing framework to write tests for you Java application. This tutorial gives
you an overview of the features of JUnit and shows a little example how you can write tests for
your Java application.
General
Author:
Sascha Wolski
Sebastian Hennebrueder
http://www.laliluna.de/tutorials.html – Tutorials for Struts, EJB, xdoclet and eclipse.
Date:
April, 12 2005
Software:
Eclipse 3.x
Junit 2.x
Source code:
http://www.laliluna.de/assets/tutorials/junit-testing-source.zip
PDF Version
http://www.laliluna.de/assets/tutorials/junit-testing-en.pdf
What is JUnit
JUnit is a simple open source Java testing framework used to write and run repeatable automated
tests. It is an instance of the xUnit architecture for unit testing framework. Eclipse supports
creating test cases and running test suites, so it is easy to use for your Java applications.
JUnit features include:
• Assertions for testing expected results
• Test fixtures for sharing common test data
• Test suites for easily organizing and running tests
• Graphical and textual test runners
What is a test case
A test case is a class which holds a number of test methods. For example if you want to test some
methods of a class Book you create a class BookTest which extends the JUnit TestCase class and
place your test methods in there.
How you write and run a simple test
1. Create a subclass of TestCase:
public class BookTest extends TestCase{
//..
}
2. Write a test method to assert expected results on the object under test:
Note: The naming convention for a test method is testXXX()
public void testCollection() {
Collection collection = new ArrayList();
assertTrue(collection.isEmpty());
}
3. Write a suite() method that uses reflection to dynamically create a test suite containing all the
testXXX() methods:
public static Test suite(){
return new TestSuite(BookTest.class);
}
4. Activate the JUnit view in Eclipse (Window > Show View > Other.. > Java > JUnit).

You find the JUnit tab near the Package Explorer tab. You can change the position of the tab by
drag and drop it.
5. Right click on the subclass of TestCase and choose Run > JUnit Test to run the test.
Using a test fixture
A test fixture is useful if you have two or more tests for a common set of objects. Using a test
fixture avoids duplicating the test code necessary to initialize and cleanup those common objects
for each test.
To create a test fixture, define a setUp() method that initializes common object and a tearDown()
method to cleanup those objects. The JUnit framework automatically invokes the setUp() method
before a each test is run and the tearDown() method after each test is run.
The following test uses a test fixture:
public class BookTest2 extends TestCase {
private Collection collection;
protected void setUp() {
collection = new ArrayList();
}
protected void tearDown() {
collection.clear();
}
public void testEmptyCollection(){
assertTrue(collection.isEmpty());
}
}
Dynamic and static way of running single tests
JUnit supports two ways (static and dynamic) of running single tests.
In static way you override the runTest() method inherited form TestCase class and call the desired
test case. A convenient way to do this is with an anonymous inner class.
Note: Each test must be given a name, so you can identify it if it fails.
TestCase test = new BookTest("equals test") {
public void runTest() {
testEquals();
}
};
The dynamic way to create a test case to be run uses reflection to implement runTest. It assumes
the name of the test is the name of the test case method to invoke. It dynamically finds and
invokes the test method. The dynamic way is more compact to write but it is less static type safe.
An error in the name of the test case goes unnoticed until you run it and get a
NoSuchMethodException. We leave the choice of which to use up to you.
TestCast test = new BookTest("testEquals");
What is a TestSuite
If you have two tests and you'll run them together you could run the tests one at a time yourself,
but you would quickly grow tired of that. Instead, JUnit provides an object TestSuite which runs
any number of test cases together. The suite method is like a main method that is specialized to
run tests.
Create a suite and add each test case you want to execute:
public static void suite(){
TestSuite suite = new TestSuite();
suite.addTest(new BookTest("testEquals"));
suite.addTest(new BookTest("testBookAdd"));
return suite;
}
Since JUnit 2.0 there is an even simpler way to create a test suite, which holds all testXXX()
methods. You only pass the class with the tests to a TestSuite and it extracts the test methods
automatically.
Note: If you use this way to create a TestSuite all test methods will be added. If you do not want all
test methods in the TestSuite use the normal way to create it.
Example:
public static void suite(){
return new TestSuite(BookTest.class);
}
A little example
Create a new Java project named JUnitExample.
Add a package de.laliluna.tutorial.junitexample where you place the example classes and a
package test.laliluna.tutorial.junitexample where you place your test classes.
The class Book
Create a new class Book in the package de.laliluna.tutorial.junitexample.
Add two properties title of type String and price of type double.
Add a constructor to set the two properties.
Provide a getter- and setter-method for each of them.
Add a method trunk for a method equals(Object object) which checks if the object is an instance of
the class Book and the values of the object are equal. The method return a boolean value.
Note: Do not write the logic of the equals(..) method, we do it after finish creating the test method.
The following source code shows the class Book.
public class Book {
private String title;
private double price;
/**
* Constructor
*
* @param title
* @param price
*/
public Book(String title,
double price) {
this.title = title;
this.price = price;
}
/**
* Check if an object is an instance of book
* and the values of title and price are equal
* then return true, otherwise return false
*/
public boolean equals(Object object) {
return false;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
The test case BookTest
Create a new test case BookTest in the package test.laliluna.tutorial.junitexample Right click on
the package and choose New > JUnit Test Case.
In the wizard choose the methods stubs setUp(), tearDown() and constructor().
The following source code shows the class BookTest
public class BookTest extends TestCase {
/**
* setUp() method that initializes common objects
*/
protected void setUp() throws Exception {
super.setUp();
}
/**
* tearDown() method that cleanup the common objects
*/
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* Constructor for BookTest.
* @param name
*/
public BookTest(String name) {
super(name);
}
}
Now we want to write a test for the equals(..) method of the class Book. We provide three private
properties, book1, book2 and book3 of type Book.
private Book book1;
private Book book2;
private Book book3;
Within the setUp() method we initializes the three properties with some values. Property book1
and book3 are the same.
protected void setUp() throws Exception {
super.setUp();
book1 = new Book("ES", 12.99);
book2 = new Book("The Gate", 11.99);
book3 = new Book("ES", 12.99);
}
Within the tearDown() method we cleanup the properties:
protected void tearDown() throws Exception {
super.tearDown();
book1 = null;
book2 = null;
book3 = null;
}
Now, add a test method testEquals() to the test case. Within the method we use the assertFalse()
method of the JUnit framework to test if the return-value of the equals(..) method is false, because
book1 and book2 are not the same. If the return-value is false the logic of the equals() method is
correct, otherwise there is a logical problem while comparing the objects. We want to test if the
method compares the objects correctly by using the assertTrue() method. Book1 and Book3 are
the same, because both are an instance of the class Book and have the same values.
The following source code shows the testEquals() method:
public void testEquals(){
assertFalse(book2.equals(book1));
assertTrue(book1.equals(book1));
}
Writing the logic of the equals() method
We have finished the test and now we can add the logic to the equals() method stub. Open the
class Book and add the logic to the equals() method. First we check if the object given by the
method is an instance of Book. Then compare the properties title and price, if they are equal
return true.
public boolean equals(Object object) {
if (object instanceof Book) {
Book book = (Book) object;
return getTitle().equals(book.getTitle())
&& getPrice() == book.getPrice();
}
return false;
}
Create the suite() method
In order to run the test method testEquals() add a method suite() to the class BookTest.
Note: You can also create a separate class where you add the suite() method.
Within the method create a new instance of TestSuite and use the method addTest(..) to add a
test. Here we use the dynamically way to add a test to a TestSuite.
The method looks like the follows:
public static Test suite(){
TestSuite suite = new TestSuite();
suite.addTest(new BookTest("testEquals"));
return suite;
}
Run the test
After finishing all test methods we want to run the JUnit test case. Right mouse button on the class
BookTest and choose Run As > JUnit Test.
On the JUnit view (Menu Windows -> show view) of Eclipse you can see how many runs, errors
and failures occurred.

Types of JDBC Drivers

JDBC drivers are divided into four types or levels. The different types of jdbc drivers are:

Type 1: JDBC-ODBC Bridge driver (Bridge)
Type 2: Native-API/partly Java driver (Native)
Type 3: AllJava/Net-protocol driver (Middleware)
Type 4: All Java/Native-protocol driver (Pure)


4 types of jdbc drivers are elaborated in detail as shown below:

Type 1 JDBC Driver

JDBC-ODBC Bridge driver

The Type 1 driver translates all JDBC calls into ODBC calls and sends them to the ODBC driver. ODBC is a generic API. The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available.


Type 1: JDBC-ODBC Bridge

Advantage

The JDBC-ODBC Bridge allows access to almost any database, since the database’s ODBC drivers are already available.

Disadvantages

1. Since the Bridge driver is not written fully in Java, Type 1 drivers are not portable.
2. A performance issue is seen as a JDBC call goes through the bridge to the ODBC driver, then to the database, and this applies even in the reverse process. They are the slowest of all driver types.
3. The client system requires the ODBC Installation to use the driver.
4. Not good for the Web.

Type 2 JDBC Driver

Native-API/partly Java driver

The distinctive characteristic of type 2 jdbc drivers are that Type 2 drivers convert JDBC calls into database-specific calls i.e. this driver is specific to a particular database. Some distinctive characteristic of type 2 jdbc drivers are shown below. Example: Oracle will have oracle native api.


Type 2: Native api/ Partly Java Driver

Advantage

The distinctive characteristic of type 2 jdbc drivers are that they are typically offer better performance than the JDBC-ODBC Bridge as the layers of communication (tiers) are less than that of Type
1 and also it uses Native api which is Database specific.

Disadvantage

1. Native API must be installed in the Client System and hence type 2 drivers cannot be used for the Internet.
2. Like Type 1 drivers, it’s not written in Java Language which forms a portability issue.
3. If we change the Database we have to change the native api as it is specific to a database
4. Mostly obsolete now
5. Usually not thread safe.

Type 3 JDBC Driver

All Java/Net-protocol driver

Type 3 database requests are passed through the network to the middle-tier server. The middle-tier then translates the request to the database. If the middle-tier server can in turn use Type1, Type 2 or Type 4 drivers.


Type 3: All Java/ Net-Protocol Driver

Advantage

1. This driver is server-based, so there is no need for any vendor database library to be present on client machines.
2. This driver is fully written in Java and hence Portable. It is suitable for the web.
3. There are many opportunities to optimize portability, performance, and scalability.
4. The net protocol can be designed to make the client JDBC driver very small and fast to load.
5. The type 3 driver typically provides support for features such as caching (connections, query results, and so on), load balancing, and advanced
system administration such as logging and auditing.
6. This driver is very flexible allows access to multiple databases using one driver.
7. They are the most efficient amongst all driver types.

Disadvantage

It requires another server application to install and maintain. Traversing the recordset may take longer, since the data comes through the backend server.

Type 4 JDBC Driver

Native-protocol/all-Java driver

The Type 4 uses java networking libraries to communicate directly with the database server.


Type 4: Native-protocol/all-Java driver

Advantage

1. The major benefit of using a type 4 jdbc drivers are that they are completely written in Java to achieve platform independence and eliminate deployment administration issues. It is most suitable for the web.
2. Number of translation layers is very less i.e. type 4 JDBC drivers don’t have to translate database requests to ODBC or a native connectivity interface or to pass the request on to another server, performance is typically quite good.
3. You don’t need to install special software on the client or server. Further, these drivers can be downloaded dynamically.

Disadvantage

With type 4 drivers, the user needs a different driver for each database.