Results 1 to 4 of 4
  1. #1
    rupeshkadam is offline Member
    Join Date
    Aug 2014
    Posts
    2
    Rep Power
    0

    Post servlet question on session.

    i hv created login page and session. when i going to access "NextServlet" directly it will not passing me to login page. instant of that it will giving me error as null pointer exception. and i check all the web-app. some one pls tell me what is wrong with this


    this is login page
    <html>
    <body>
    <form action="sed" method="get">
    username:<input type="text" name="txtn"><br/>
    pass:<input type="password" name="txtp">
    <input type="submit" value="submit">
    </form>
    </body>
    </html>


    this is for creating session
    package com.student;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class SessionDemo extends HttpServlet{
    @Override
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException{
    HttpSession s=request.getSession(true);
    s.setAttribute("unamesession","rupesh");
    response.sendRedirect("ns");
    }
    }



    and this is for recognizing session
    package com.student;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class NextServlet extends HttpServlet{
    @Override
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException{
    PrintWriter out=response.getWriter();
    HttpSession s1=request.getSession(false);
    String user=(String)s1.getAttribute("unamesession");
    if(user==null){
    response.sendRedirect("Login.html");
    }else{
    out.println("welcome to my new world");
    }
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: servlet question on session.

    When posting code please wrap the code in [code] tags [/code] so it retains its formatting.

    If you are getting an exception then you should post the full exception here, including stack trace, and point out which line in your code it is thrown from.

    Are you sure you want to do a redirect and not a forward?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    rupeshkadam is offline Member
    Join Date
    Aug 2014
    Posts
    2
    Rep Power
    0

    Default Re: servlet question on session.

    yes i m sure i want to redirect.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: servlet question on session.

    OK.
    That still leaves the other bits of my post.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 06-09-2013, 06:12 PM
  2. Calculate the sum of elements in servlet session
    By Galichka in forum Advanced Java
    Replies: 4
    Last Post: 05-22-2012, 12:10 PM
  3. Get session attributes in servlet while using multiplart/form-data tag is JSP
    By jason.3dmagic in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 12-01-2010, 07:57 AM
  4. share session object between servlet and jsp
    By sameerk in forum Java Servlet
    Replies: 6
    Last Post: 09-29-2010, 11:20 AM
  5. session in servlet
    By erakhman in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-14-2010, 06:20 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
  •