Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Post how to create session in jsp

    Dear Sir

    I am creating a user interface and want to create session for the different user . but didn't get how to create a session
    please how to do session ?
    please reply..............

  2. #2
    bhaskary is offline Member
    Join Date
    Apr 2008
    Location
    hyderabad
    Posts
    11
    Rep Power
    0

    Default

    HttpSession session=req.getSession(true);
    String sessionID=session.getId();

  3. #3
    sivaranjani is offline Member
    Join Date
    Dec 2008
    Posts
    1
    Rep Power
    0

    Default

    HttpSession session = req.getSession(true);

  4. #4
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    here run this program u will understand
    <HTML>
    <HEAD> <TITLE>Login using jsp</TITLE> </HEAD>
    <BODY>
    <H1>LOGIN FORM</H1>
    <% String myname = (String)session.getAttribute("username");
    if(myname!=null) {
    out.println("Welcome "+myname+" , <a href=\"logout.jsp\" >Logout</a>");
    } else { %>
    <form action="checkLogin.jsp">
    <table>
    <tr> <td> Username : </td><td> <input name="username" size=15 type="text" /> </td> </tr>
    <tr> <td> Password : </td><td> <input name="password" size=15 type="text" /> </td> </tr>
    </table>
    <input type="submit" value="login" />
    </form>
    <% } %>
    </BODY>
    </HTML>


    <%
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    out.println("Checking login<br>");
    if (username == null || password == null) {

    out.print("Invalid paramters ");
    }

    // Here you put the check on the username and password
    if (username.toLowerCase().trim().equals("admin") && password.toLowerCase().trim().equals("admin")) {
    out.println("Welcome " + username + " <a href=\"index.jsp\">Back to main</a>");
    session.setAttribute("username", username);
    }
    else
    {
    out.println("Invalid username and password");
    }
    %>


    <%

    String username=(String)session.getAttribute("username");
    if(username!=null)
    {
    out.println(username+" loged out, <a href=\"index.jsp\">Back</a>");
    session.removeAttribute("username");

    }
    else
    {
    out.println("You are already not login <a href=\"index.jsp\">Back</a>");
    }
    %>

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

Similar Threads

  1. session
    By jm_it04 in forum AWT / Swing
    Replies: 0
    Last Post: 03-04-2008, 11:32 AM
  2. JSP - session variables
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-02-2007, 09:22 PM
  3. Session Expiry
    By Jack in forum Web Frameworks
    Replies: 1
    Last Post: 07-09-2007, 04:08 AM
  4. Use session
    By Eric in forum Java Servlet
    Replies: 1
    Last Post: 07-05-2007, 08:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •