PawelK 0 Newbie Poster

I have problem with Java session. I have a TplanServlet where I request values from html form and I am going to create Monday object with createMonday(). So I pass my form to this sevlet

if (option.equalsIgnoreCase("createMonday")) {
                String title = request.getParameter("tpName");

                String g1 = request.getParameter("g1");
                String a1 = request.getParameter("a1");
                String a2 = request.getParameter("a2");
                String a3 = request.getParameter("a3");
                String a4 = request.getParameter("a4");
                String a5 = request.getParameter("a5");

                String g2 = request.getParameter("g2");
                String a6 = request.getParameter("a6");
                String a7 = request.getParameter("a7");
                String a8 = request.getParameter("a8");
                String a9 = request.getParameter("a9");
                String a10 = request.getParameter("a10");

                String g3 = request.getParameter("g3");
                String a11 = request.getParameter("a11");
                String a12 = request.getParameter("a12");
                String a13 = request.getParameter("a13");
                String a14 = request.getParameter("a14");
                String a15 = request.getParameter("a15");

                String mondayId = request.getParameter("mondayId");

                m = new Monday(g1, a1, a2, a3, a4, a5, g2, a6, a7, a8, a9, a10, g3, a11, a12, a13, a14, a15);
                boolean saved = m.createMonday();
                session.setAttribute("Monday", m);
                session.setAttribute("tpName", title);
                session.setAttribute("mondayId", mondayId);
                String uId = (String) session.getAttribute("id");
                u = u.findUserById(uId);
                request.setAttribute("Users", u);

                System.out.println("Monday!!!: " + m.getMondayId() + " has been created!"); //print m.getMondayId() ok!!!

                if (m.getMondayId() != null) {
                    System.out.println("Monday idd: " + m.getMondayId());
                    address = "ctraining2.jsp";

                } else {
                    System.out.println("MONAY not created");
                    address = "invalid.jsp";
                }

            }

This seved to db Monday object, print m.getMondayId() with System.out.println("Monday!!!: " + m.getMondayId() + " has been created!"); and redirecting me to ctraining2.jsp. And here my problems start. On ctraining2.jsp I can display my session attributes

<h3> TPLAN NAME: <%= session.getAttribute("tpName")%></h3>
<h3> USER ID: <%= session.getAttribute("id")%></h3>
<h3> MONDAY : <%= session.getAttribute("Monday")%></h3>

But can't display this

<h3> MONDAY ID: <%= session.getAttribute("mondayId")%></h3>

I can't see where is error? Why mondayId want display?

In the next step (ctraining2.jsp) I grab some more values (privateplan) from another form and passing to my servlet

else if (option.equalsIgnoreCase("createTplan")) {

                String tName = (String) session.getAttribute("tpName");
                String uId = (String) session.getAttribute("id");
                String privateplan = request.getParameter("privateplan");
                String mondayId = (String) session.getAttribute("mondayId");

                t = new TPlans(tName, uId, privateplan, mondayId);
                boolean saved = t.createTplan();

                session.setAttribute("mondayId", mondayId);

                System.out.println("Monday tplan: " + t.gettName());
                System.out.println("uid: " + t.getuId());
                System.out.println("private: " + t.getPrivateplan());
                System.out.println("mondayId: " + t.getMondayId());
                if (t.getMondayId() != null) {
                    System.out.println(t.getMondayId());
                    System.out.println("Monday tplan: " + t.gettName() + " has been created");
                    address = "ctraining3.jsp";

                } else {
                    System.out.println("tplan not created");
                    address = "invalid.jsp";
                }

            }

and again I can print

System.out.println("Monday tplan: " + t.gettName());
System.out.println("uid: " + t.getuId());
System.out.println("private: " + t.getPrivateplan());

but can't print

System.out.println("mondayId: " + t.getMondayId());

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.