ࡱ > [ bjbj 4 ΐ ΐ , f $ y : . . . . . . . hN5A . ~ 0 . U @ U . U . P . . U : @ Exp 15.3
Develop a program to accept usrname and password
//Client form
//servlet
import java.io.*;
import javax.servlet.*;
public class GenericServletDemo extends GenericServlet
{
public void service(ServletRequest request ,ServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("");
out.println("hello page");
out.println("");
String name=(String) request.getParameter("user1");
String password=(String) request.getParameter("password1");
out.println("Name="+name+"
");
out.println("Passsword="+password+"
");
out.println("");
}
}
web.xml
GenericServletDemo
GenericServletDemo
GenericServletDemo
/servlet/GenericServletDemo
Output:
Exp 15.4
Develop a program to authenticate the user name and password
//Client form
//servlet
import java.io.*;
import javax.servlet.*;
public class GenericServletDemo2 extends GenericServlet
{
public void service(ServletRequest request ,ServletResponse response)
throws ServletException,IOException
{
String uname="Prasad";
String pass="123456";
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("");
out.println("hello page");
out.println("");
String name=(String) request.getParameter("user1");
String password=(String) request.getParameter("password1");
if((name.equals(uname))&&(password.equals(pass)))
{
out.println("Welcome "+name);
}
else
{
out.println("Invalid username or password");
}
out.println("");
}
}
Output:
When Valid user
When Invalid User
9 :
%
&
'
)
*
+
4
z
, c d Ǽߋxxxx߀pldl j h& Uh& j h& Uh& CJ aJ h& h& CJ aJ hO hH 5>*CJ aJ h& 5>*CJ aJ j*0 h Uj h Uh hH hO h CJ aJ h CJ aJ hH CJ aJ h? CJ aJ hO hH CJ aJ hH 5>*CJ aJ h 5>*CJ aJ &