SlideShare a Scribd company logo
1 of 28
Download to read offline
SiteHome.html
<html>
<head>
<title>URL Rewriting Example</title>
</head>
<body>
This is the Home page for the example to demonstrate how
to use <BR>
URL Rewriting and Hidden form fields to mantain the client
state. <BR><BR>
<a href="Login.html">Login</a>
</body>
</html>
Login.html
<html>
<head>
<title>URL Rewriting Example</title>
</head>
<body>
<form name="loginform" action="login" method="post">
<table border="0">
<tr>
<td>UserName:</td>
<td><input type="text" name="uname"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit"></td>
</tr>
</table>
</form>
</body>
</html>
• Once you click on submit button
• Post method is executed, data is submitted
into server in the form of request object
• Later LoginServlet program gets executed
because of <form action=“login”> whose url
pattern servlet name is “LoginServlet” (see
web.xml file)
LoginServlet.java
package com.rajendra.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String uname=request.getParameter("uname");
String pass=request.getParameter("password");
LoginServlet.java
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println(" <HEAD><TITLE>A
Servlet</TITLE></HEAD>");
out.println(" <BODY>");
LoginServlet.java
if (uname==null||uname.equals("")){
out.println("<b><i>Username Cannot be empty</i></b>");
RequestDispatcher rd=request.getRequestDispatcher("/Login.html");
rd.include(request, response);
return;
}
if (pass==null||pass.equals("")){
out.println("<b><i>Password Cannot be empty</i></b>");
RequestDispatcher rd=request.getRequestDispatcher("/Login.html");
rd.include(request, response);
return;
}
UserDAO ud=new UserDAO();
LoginServlet.java
if(ud.validate(uname,pass)){
out.println("<table width=98% height=95% border=1><tr>");
out.println("<td height=45 colspan=2 align=center><font size=5>My Email
Site</font></td>");
out.println("</tr><tr>");
out.println("<td width=12% height=545 align=center valign=top>");
out.println("<p>&nbsp;</p><p><font size=4>");
out.println("<a href='inbox?uname="+uname+"'>InBox</a>");
out.println("</font></p>");
out.println("<p><font size=4>Bulk Mail</font></p>");
out.println("<p><font size=4>Sent Items</font></p>");
out.println("<p><font size=4>Write Mail</font></p>");
out.println("<p><font size=4><a href='Login.html'>Logout</a></font></p>");
out.println("<p>&nbsp;</p></td>");
out.println("<td width=88% align=left valign=top><p>&nbsp;</p>");
out.println("<p><font size=4>Welcome, "+uname+"</font></p></td>");
out.println("</tr><tr align=center>");
out.println("<td colspan=2><div align=center>@Copyrights 2001-08</div></td>");
out.println("</tr></table>");
LoginServlet.java
}//if
else{
out.println("<b><i>Username or Password given are not valid</i></b>");
RequestDispatcher rd=request.getRequestDispatcher("/Login.html");
rd.include(request, response);
return;
}
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
• Now servlet container calls the public service()
and which intern calls the protected service()
method
• Protected service() calls doPost() method
• Now if() conditions becomes false, (server side
validation for username and password).
• Now UserDao object is created to call
validate() method
LoginServlet.java
if(ud.validate(uname,pass))
• if(ud.validate(uname,pass))
• if(ud.validate(rajendra,raj)) method calling
• Now control goes to validate () method in
UserDao class
UserDAO.java
package com.rajendra.servlets;
import java.sql.*;
public class UserDAO {
public boolean validate(String uname, String pass){
try {
Connection con=DriverConnection.getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(
"select count(*) from userdetails where
uname='"+uname+"' and pass='"+pass+"'");
return rs.next();
}//try
catch(Exception e){
e.printStackTrace();
}
return false;
}
}
• return rs.next();
• return true;//it returns true as resultset
contains next element
• Now control come back to the
LoginServlet.java
if(ud.validate(uname,pass)){ //if condition becomes true
out.println("<table width=98% height=95% border=1><tr>");
out.println("<td height=45 colspan=2 align=center><font size=5>My Email
Site</font></td>");
out.println("</tr><tr>");
out.println("<td width=12% height=545 align=center valign=top>");
out.println("<p>&nbsp;</p><p><font size=4>");
out.println("<a href='inbox?uname="+uname+"'>InBox</a>");
out.println("</font></p>");
out.println("<p><font size=4>Bulk Mail</font></p>");
out.println("<p><font size=4>Sent Items</font></p>");
out.println("<p><font size=4>Write Mail</font></p>");
out.println("<p><font size=4><a href='Login.html'>Logout</a></font></p>");
out.println("<p>&nbsp;</p></td>");
out.println("<td width=88% align=left valign=top><p>&nbsp;</p>");
out.println("<p><font size=4>Welcome, "+uname+"</font></p></td>");
out.println("</tr><tr align=center>");
out.println("<td colspan=2><div align=center>@Copyrights 2001-08</div></td>");
out.println("</tr></table>");
Sessionex1

More Related Content

What's hot

Rounded Shaped Box Example 1
Rounded Shaped Box Example 1Rounded Shaped Box Example 1
Rounded Shaped Box Example 1Sibananda Panda
 
Getting Information through HTML Forms
Getting Information through HTML FormsGetting Information through HTML Forms
Getting Information through HTML FormsMike Crabb
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In PhpHarit Kothari
 
Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)Linux User's Group
 
HTML frames and HTML forms
HTML frames and HTML formsHTML frames and HTML forms
HTML frames and HTML formsNadine Cruz
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTMLMarlon Jamera
 
Html table tags
Html table tagsHtml table tags
Html table tagseShikshak
 
Chapter 07 php forms handling
Chapter 07   php forms handlingChapter 07   php forms handling
Chapter 07 php forms handlingDhani Ahmad
 
HTML 5 Tables and Forms
HTML 5 Tables and FormsHTML 5 Tables and Forms
HTML 5 Tables and FormsDoncho Minkov
 
HTML Powerpoint-Jeffrey C. Johnson III
HTML Powerpoint-Jeffrey C. Johnson IIIHTML Powerpoint-Jeffrey C. Johnson III
HTML Powerpoint-Jeffrey C. Johnson IIIjeffcarlj
 

What's hot (19)

Rounded Shaped Box Example 1
Rounded Shaped Box Example 1Rounded Shaped Box Example 1
Rounded Shaped Box Example 1
 
Getting Information through HTML Forms
Getting Information through HTML FormsGetting Information through HTML Forms
Getting Information through HTML Forms
 
HTML5 Web Forms
HTML5 Web FormsHTML5 Web Forms
HTML5 Web Forms
 
HTML 4.0
HTML 4.0HTML 4.0
HTML 4.0
 
Html 5 Forms
Html 5 FormsHtml 5 Forms
Html 5 Forms
 
Html Table
Html TableHtml Table
Html Table
 
Html tag list
Html tag listHtml tag list
Html tag list
 
Html 5 tags
Html  5 tagsHtml  5 tags
Html 5 tags
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
html-table
html-tablehtml-table
html-table
 
Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)
 
HTML frames and HTML forms
HTML frames and HTML formsHTML frames and HTML forms
HTML frames and HTML forms
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTML
 
Html tags describe in bangla
Html tags describe in banglaHtml tags describe in bangla
Html tags describe in bangla
 
Html table tags
Html table tagsHtml table tags
Html table tags
 
Chapter 07 php forms handling
Chapter 07   php forms handlingChapter 07   php forms handling
Chapter 07 php forms handling
 
HTML 5 Tables and Forms
HTML 5 Tables and FormsHTML 5 Tables and Forms
HTML 5 Tables and Forms
 
5.1 html lec 5
5.1 html lec 55.1 html lec 5
5.1 html lec 5
 
HTML Powerpoint-Jeffrey C. Johnson III
HTML Powerpoint-Jeffrey C. Johnson IIIHTML Powerpoint-Jeffrey C. Johnson III
HTML Powerpoint-Jeffrey C. Johnson III
 

Viewers also liked

Viewers also liked (8)

Class
ClassClass
Class
 
Exceptions
ExceptionsExceptions
Exceptions
 
Class
ClassClass
Class
 
Get data
Get dataGet data
Get data
 
Interface connection
Interface connectionInterface connection
Interface connection
 
Different waysconnect
Different waysconnectDifferent waysconnect
Different waysconnect
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
2. attributes
2. attributes2. attributes
2. attributes
 

Similar to Sessionex1

Caracteristicas Basicas De Htlm
Caracteristicas Basicas De HtlmCaracteristicas Basicas De Htlm
Caracteristicas Basicas De HtlmMaria S Rivera
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivityMouli Chandira
 
data insert in codeigniter.pptx
data insert in codeigniter.pptxdata insert in codeigniter.pptx
data insert in codeigniter.pptxfeesfesfesf
 
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docxsri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docxwhitneyleman54422
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckAnthony Montalbano
 
INTRODUCTION TO HTML & CSS .pptx
INTRODUCTION TO HTML & CSS .pptxINTRODUCTION TO HTML & CSS .pptx
INTRODUCTION TO HTML & CSS .pptxSarthakrOkr
 
HTML SERVER CONTROL - ASP.NET WITH C#
HTML SERVER CONTROL  - ASP.NET WITH C#HTML SERVER CONTROL  - ASP.NET WITH C#
HTML SERVER CONTROL - ASP.NET WITH C#priya Nithya
 
Html server control - ASP. NET with c#
Html server control - ASP. NET with c#Html server control - ASP. NET with c#
Html server control - ASP. NET with c#priya Nithya
 
Form & frame
Form & frameForm & frame
Form & frameaminsir
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to BootstrapRon Reiter
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-KjaerCOMMON Europe
 

Similar to Sessionex1 (20)

Lab final
Lab finalLab final
Lab final
 
Caracteristicas Basicas De Htlm
Caracteristicas Basicas De HtlmCaracteristicas Basicas De Htlm
Caracteristicas Basicas De Htlm
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivity
 
Delete statement in PHP
Delete statement in PHPDelete statement in PHP
Delete statement in PHP
 
Lect# 1 html part ii
Lect# 1 html part iiLect# 1 html part ii
Lect# 1 html part ii
 
Update statement in PHP
Update statement in PHPUpdate statement in PHP
Update statement in PHP
 
data insert in codeigniter.pptx
data insert in codeigniter.pptxdata insert in codeigniter.pptx
data insert in codeigniter.pptx
 
Practicals it
Practicals itPracticals it
Practicals it
 
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docxsri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages Suck
 
INTRODUCTION TO HTML & CSS .pptx
INTRODUCTION TO HTML & CSS .pptxINTRODUCTION TO HTML & CSS .pptx
INTRODUCTION TO HTML & CSS .pptx
 
1cst
1cst1cst
1cst
 
HTML SERVER CONTROL - ASP.NET WITH C#
HTML SERVER CONTROL  - ASP.NET WITH C#HTML SERVER CONTROL  - ASP.NET WITH C#
HTML SERVER CONTROL - ASP.NET WITH C#
 
Html server control - ASP. NET with c#
Html server control - ASP. NET with c#Html server control - ASP. NET with c#
Html server control - ASP. NET with c#
 
Intodcution to Html
Intodcution to HtmlIntodcution to Html
Intodcution to Html
 
Form & frame
Form & frameForm & frame
Form & frame
 
Unit 1wt
Unit 1wtUnit 1wt
Unit 1wt
 
Unit 1wt
Unit 1wtUnit 1wt
Unit 1wt
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 

More from myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 
Properties
PropertiesProperties
Properties
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
 
Interface callable statement
Interface callable statementInterface callable statement
Interface callable statement
 

Recently uploaded

Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxMadhavi Dharankar
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptx4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptxmary850239
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
An Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERPAn Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERPCeline George
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6Vanessa Camilleri
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...Nguyen Thanh Tu Collection
 
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...Nguyen Thanh Tu Collection
 
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...HetalPathak10
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEMISSRITIMABIOLOGYEXP
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Osopher
 

Recently uploaded (20)

Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptx
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptx4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptx
 
Spearman's correlation,Formula,Advantages,
Spearman's correlation,Formula,Advantages,Spearman's correlation,Formula,Advantages,
Spearman's correlation,Formula,Advantages,
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
An Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERPAn Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERP
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
 
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
 
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
 

Sessionex1

  • 1.
  • 2. SiteHome.html <html> <head> <title>URL Rewriting Example</title> </head> <body> This is the Home page for the example to demonstrate how to use <BR> URL Rewriting and Hidden form fields to mantain the client state. <BR><BR> <a href="Login.html">Login</a> </body> </html>
  • 3.
  • 4. Login.html <html> <head> <title>URL Rewriting Example</title> </head> <body> <form name="loginform" action="login" method="post"> <table border="0"> <tr> <td>UserName:</td> <td><input type="text" name="uname"></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit"></td> </tr> </table> </form> </body> </html>
  • 5.
  • 6.
  • 7.
  • 8. • Once you click on submit button • Post method is executed, data is submitted into server in the form of request object • Later LoginServlet program gets executed because of <form action=“login”> whose url pattern servlet name is “LoginServlet” (see web.xml file)
  • 9. LoginServlet.java package com.rajendra.servlets; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.*; import javax.servlet.http.*; public class LoginServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uname=request.getParameter("uname"); String pass=request.getParameter("password");
  • 10. LoginServlet.java response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>");
  • 11. LoginServlet.java if (uname==null||uname.equals("")){ out.println("<b><i>Username Cannot be empty</i></b>"); RequestDispatcher rd=request.getRequestDispatcher("/Login.html"); rd.include(request, response); return; } if (pass==null||pass.equals("")){ out.println("<b><i>Password Cannot be empty</i></b>"); RequestDispatcher rd=request.getRequestDispatcher("/Login.html"); rd.include(request, response); return; } UserDAO ud=new UserDAO();
  • 12. LoginServlet.java if(ud.validate(uname,pass)){ out.println("<table width=98% height=95% border=1><tr>"); out.println("<td height=45 colspan=2 align=center><font size=5>My Email Site</font></td>"); out.println("</tr><tr>"); out.println("<td width=12% height=545 align=center valign=top>"); out.println("<p>&nbsp;</p><p><font size=4>"); out.println("<a href='inbox?uname="+uname+"'>InBox</a>"); out.println("</font></p>"); out.println("<p><font size=4>Bulk Mail</font></p>"); out.println("<p><font size=4>Sent Items</font></p>"); out.println("<p><font size=4>Write Mail</font></p>"); out.println("<p><font size=4><a href='Login.html'>Logout</a></font></p>"); out.println("<p>&nbsp;</p></td>"); out.println("<td width=88% align=left valign=top><p>&nbsp;</p>"); out.println("<p><font size=4>Welcome, "+uname+"</font></p></td>"); out.println("</tr><tr align=center>"); out.println("<td colspan=2><div align=center>@Copyrights 2001-08</div></td>"); out.println("</tr></table>");
  • 13. LoginServlet.java }//if else{ out.println("<b><i>Username or Password given are not valid</i></b>"); RequestDispatcher rd=request.getRequestDispatcher("/Login.html"); rd.include(request, response); return; } out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } }
  • 14. • Now servlet container calls the public service() and which intern calls the protected service() method • Protected service() calls doPost() method
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. • Now if() conditions becomes false, (server side validation for username and password). • Now UserDao object is created to call validate() method
  • 21. if(ud.validate(uname,pass)) • if(ud.validate(uname,pass)) • if(ud.validate(rajendra,raj)) method calling • Now control goes to validate () method in UserDao class
  • 22. UserDAO.java package com.rajendra.servlets; import java.sql.*; public class UserDAO { public boolean validate(String uname, String pass){ try { Connection con=DriverConnection.getConnection(); Statement st=con.createStatement(); ResultSet rs=st.executeQuery( "select count(*) from userdetails where uname='"+uname+"' and pass='"+pass+"'"); return rs.next(); }//try catch(Exception e){ e.printStackTrace(); } return false; } }
  • 23.
  • 24.
  • 25.
  • 26. • return rs.next(); • return true;//it returns true as resultset contains next element • Now control come back to the LoginServlet.java
  • 27. if(ud.validate(uname,pass)){ //if condition becomes true out.println("<table width=98% height=95% border=1><tr>"); out.println("<td height=45 colspan=2 align=center><font size=5>My Email Site</font></td>"); out.println("</tr><tr>"); out.println("<td width=12% height=545 align=center valign=top>"); out.println("<p>&nbsp;</p><p><font size=4>"); out.println("<a href='inbox?uname="+uname+"'>InBox</a>"); out.println("</font></p>"); out.println("<p><font size=4>Bulk Mail</font></p>"); out.println("<p><font size=4>Sent Items</font></p>"); out.println("<p><font size=4>Write Mail</font></p>"); out.println("<p><font size=4><a href='Login.html'>Logout</a></font></p>"); out.println("<p>&nbsp;</p></td>"); out.println("<td width=88% align=left valign=top><p>&nbsp;</p>"); out.println("<p><font size=4>Welcome, "+uname+"</font></p></td>"); out.println("</tr><tr align=center>"); out.println("<td colspan=2><div align=center>@Copyrights 2001-08</div></td>"); out.println("</tr></table>");

Editor's Notes

  1. LoginServlet.java
  2. Stringuname=request.getParameter(“uname”);String pass=request.getParameter(“pass”);
  3. LoginServlet.java