Practical 17

 avatar
Rohit143
plain_text
2 years ago
2.1 kB
17
Indexable
Never
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Login</title>
</head>
<body>
    <center>
        <h1>Rohit Nandagawali </h1>
        <h1>Enter your name </h1>
            <form action="login" method="get">  
                Name:<input type="text" name="uname"/><br/>
                <input type="submit" value="Click"/>  
            </form>  
    </center>

</body>
</html>
_________________________________________
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class practical17 extends HttpServlet{
    
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException {
        res.setContentType("text/html");
        PrintWriter pw = res.getWriter();

        String name = req.getParameter("uname");
        pw.println("Welcome  "+name);

        Cookie cookie = new Cookie("uname",name);
        res.addCookie(cookie);
        
        pw.println("<a href='page2'>click me</a>");

        pw.close();
    }
}

_________________________________________

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class practical17b extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException {
        res.setContentType("text/html");
        PrintWriter pw = res.getWriter();

        Cookie ck[] =req.getCookies();
        pw.println("Welcome again "+ck[0].getValue());
        pw.close();
    
    }
    
}
_________________________________________

<web-app>

<servlet>
<servlet-name>practical17</servlet-name>
<servlet-class>practical17</servlet-class>
</servlet>

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

<servlet>
<servlet-name>practical17b</servlet-name>
<servlet-class>practical17b</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>practical17b</servlet-name>
<url-pattern>/page2</url-pattern>
<servlet-mapping>

</web-app>