SiteHome.html
<html>
<head>
<title>URL Rewriting Example</title>
</head>
<body>
This is the Home page for the example to d...
Login.html
<html>
<head>
<title>URL Rewriting Example</title>
</head>
<body>
<form name="loginform" action="login" method=...
• Once you click on submit button
• Post method is executed, data is submitted
into server in the form of request object
•...
LoginServlet.java
package com.rajendra.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.serv...
LoginServlet.java
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out...
LoginServlet.java
if (uname==null||uname.equals("")){
out.println("<b><i>Username Cannot be empty</i></b>");
RequestDispat...
LoginServlet.java
if(ud.validate(uname,pass)){
out.println("<table width=98% height=95% border=1><tr>");
out.println("<td ...
LoginServlet.java
}//if
else{
out.println("<b><i>Username or Password given are not valid</i></b>");
RequestDispatcher rd=...
• Now servlet container calls the public service()
and which intern calls the protected service()
method
• Protected servi...
• Now if() conditions becomes false, (server side
validation for username and password).
• Now UserDao object is created t...
LoginServlet.java
if(ud.validate(uname,pass))
• if(ud.validate(uname,pass))
• if(ud.validate(rajendra,raj)) method calling
• Now control goe...
UserDAO.java
package com.rajendra.servlets;
import java.sql.*;
public class UserDAO {
public boolean validate(String uname...
• return rs.next();
• return true;//it returns true as resultset
contains next element
• Now control come back to the
Logi...
if(ud.validate(uname,pass)){ //if condition becomes true
out.println("<table width=98% height=95% border=1><tr>");
out.pri...
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Sessionex1
Upcoming SlideShare
Loading in...5
×

Sessionex1

344

Published on

Url Rewriting example program

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
344
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • LoginServlet.java
  • Stringuname=request.getParameter(“uname”);String pass=request.getParameter(“pass”);
  • LoginServlet.java
  • Sessionex1

    1. 1. 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>
    2. 2. 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>
    3. 3. • 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)
    4. 4. 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");
    5. 5. LoginServlet.java response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>");
    6. 6. 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();
    7. 7. 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>");
    8. 8. 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(); } }
    9. 9. • Now servlet container calls the public service() and which intern calls the protected service() method • Protected service() calls doPost() method
    10. 10. • Now if() conditions becomes false, (server side validation for username and password). • Now UserDao object is created to call validate() method
    11. 11. LoginServlet.java
    12. 12. 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
    13. 13. 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; } }
    14. 14. • return rs.next(); • return true;//it returns true as resultset contains next element • Now control come back to the LoginServlet.java
    15. 15. 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>");
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×