Practical 15 java

 avatar
Rohit143
plain_text
2 years ago
1.5 kB
11
Indexable
Never
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Login</title>
</head>
<body>
    <center>
        <h1>Login Here</h1>
            <form action="login" method="get">  
                Name:<input type="text" name="uname"/><br/><br/>  
                Password:<input type="password" name="pwd"/><br/><br/>  
                <input type="submit" value="login"/>  
            </form>  
    </center>

</body>
</html>
________________________________________
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Practical15 extends HttpServlet{
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{

        res.setContentType("text/html");
        PrintWriter pw = res.getWriter();
        String username = req.getParameter("uname");
        String password = req.getParameter("pwd");

        if (username.equals("Rohit") && password.equals("Pass@123")) {
            pw.println("<h1>Welcome ! "+username+"</h1>");                        
        }
        else
        {
            pw.println("<h1>Sorry username or password is incorrect</h1>");  
        }
        pw.close();
    }

    
}
________________________________________
<web-app>

<servlet>
<servlet-name>practical15</servlet-name>
<servlet-class>Practical15</servlet-class>

</servlet>

<servlet-mapping>
<servlet-name>practical15</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>

</web-app>