7 Replies Latest reply: Feb 4, 2008 4:39 AM by 807603 RSS

    HttpSession

    807603
      I am learning session using sevlet & jsp. I did a simple program to learn this.Here when I give some name and say Login it will take me to resultbean.jsp. What I am expecting is when I copy the url of resultbean.jsp and paste in new browser it must show me Log.jsp.But it gives me null.When I refresh page it gives me Log.jsp.Can anyone please help me and tell what is wrong in this and what modification I have to do?
      Log.jsp
      <%@ page session="false" %>
      <form action="login" method="POST">
      Name<input type="text" name="name">
      <input type="submit" value"Click" name="login">
      </form>

      Person.java
      package demo.person;
      public class Person{
           String name;
           public String getName(){
                return name;
           }
           public void setName(String name){
                this.name=name;
           }
      }

      resultbean.jsp
      <%@ page session="false" %>
      <%
      String name=request.getParameter("name");
      %>
      <jsp:useBean id="person" class="demo.person.Person"/>
      <jsp:setProperty name="person" property="name" value="<%=name%>" />
      Name :<jsp:getProperty name="person" property="name" />

      TestServlet.java

           public void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException     {
                HttpSession session=req.getSession(true);
                if(session.isNew()){
                     Person p=new Person();               
                     session.setAttribute("person",p);
                     System.out.println("-----If----");
                RequestDispatcher view=req.getRequestDispatcher("/resultbean.jsp");
                     view.forward(req,resp);
                }
                else{
                     session.getAttribute("person");
                     System.out.println("-----Else----");
                     RequestDispatcher view=req.getRequestDispatcher("/log.jsp");
                     view.forward(req,resp);
                }
      }


      Thank U
      Soumya
        • 1. Re: HttpSession
          807603
          A new browser instance will trigger a new session. To work in the same session, open the URL in a new window or tab of the same browser instance.
          • 2. Re: HttpSession
            807603
            BalusC wrote:
            A new browser instance will trigger a new session. To work in the same session, open the URL in a new window or tab of the same browser instance.
            That really depends on the browser. IE7 gives you a new session, Firefox uses the one you already have.
            • 3. Re: HttpSession
              807603
              pkwooster wrote:
              That really depends on the browser
              + configuration indeed.
              IE7 gives you a new session, Firefox uses the one you already have.
              IE7 is not a browser ;)
              • 4. Re: HttpSession
                807603
                why are you using "<%@ page session="false" %>"?
                • 5. Re: HttpSession
                  807603
                  BalusC wrote:
                  IE7 is not a browser ;)
                  let me know why ? Everyone says its a browser
                  (or you mean: it is not only browser but also ..)
                  • 6. Re: HttpSession
                    807603
                    In my context a real web browser respects the web standards.

                    MSIE doesn't. It introduced its own standards and quirks, causing web developers to headaches and being forced to use nasty IE specific hacks.
                    • 7. Re: HttpSession
                      807603
                      david_david wrote:
                      BalusC wrote:
                      IE7 is not a browser ;)
                      let me know why ? Everyone says its a browser
                      (or you mean: it is not only browser but also ..)
                      IE (all versions), also known as Internet Exploder, is a poor imitation of a real browser. Unfortunately, just like McD's is a poor imitation of a burger, it's also one of the most popular. So we're forced to live with it even if it causes indigestion, makes us fat, fosters global warming and prevents world peace.

                      Edited by: pkwooster on Feb 4, 2008 10:24 PM