//Login Page Validation using cookies
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Validation extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException
{
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
Cookie[] cookie=request.getCookies();
String name=request.getParameter("username");
String pass=request.getParameter("password");
String pas=" ";
for(Cookie obj:cookie)
{
if(obj.getName().equals(name))
{
pas=obj.getValue();
if(obj.getValue().equals(pass))
{
pw.println("<h1>WELCOME TO BOOK SHOP" + name +"<h1>");
break;
}
else
{
pw.println("YOU ARE INVALID USER");
break;
}
}
}
if(pas=="")
pw.println("YOU ARE INVALID USER");
}
}
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Validation extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException
{
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
Cookie[] cookie=request.getCookies();
String name=request.getParameter("username");
String pass=request.getParameter("password");
String pas=" ";
for(Cookie obj:cookie)
{
if(obj.getName().equals(name))
{
pas=obj.getValue();
if(obj.getValue().equals(pass))
{
pw.println("<h1>WELCOME TO BOOK SHOP" + name +"<h1>");
break;
}
else
{
pw.println("YOU ARE INVALID USER");
break;
}
}
}
if(pas=="")
pw.println("YOU ARE INVALID USER");
}
}
No comments:
Post a Comment