Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my project i want pass id one servlet to another servlet. here i give the two servlet.
XML
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String it="username",ac="UpdateUserDetail",sn="aucesspermision",pn1="password",pn2="confpass",m="post", t="text",st="tis",bs="styled-button",bt1="reset",bv1="clear",bt2="submit",bv2="Update",ss="select-style",p="password",r="radio",ut="usertype",rs="radio-style",v1="admin",v2="user",rt1="Admin",rt2="User",sv1="yes",sv2="no";
        String admin = null,user = null, yes=null,no=null;
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        Connection con = ConProvider.getConnection();
        HttpSession session = request.getSession();
        if (session == null) {
            response.sendRedirect("index.html");
        } else {

            request.getRequestDispatcher("header.jsp").include(request,
                    response);

            request.getRequestDispatcher("link.jsp").include(request, response);
            out.print("<form action="+ac+" method="+m+"><table  cellspacing='0'> <!-- cellspacing='0' is important, must stay -->"+ "<tr><th>Add User Details</th></tr>");

            System.out.println("workin Edit servlet");
            PreparedStatement ps;
            int id = Integer.parseInt(request.getParameter("id"));
            try {
                ps = con.prepareStatement("select * from user_details where User_details_id=?");
                ps.setInt(1, id);
                System.out.println(" edit value id=" + id);
                ResultSet rset = ps.executeQuery();
                if(rset.next()){
                    String selceted=rset.getString("User_details_type");
                    String permission=rset.getString("User_details_auccesspermission");
                    if(selceted.equals("admin"))
                    {
                         admin="selected";
                    }else if (selceted.equals("user")) {


                        user="selected";
                    }
                    if(permission.equals("yes"))
                    {
                         yes="selected";
                    }else if (permission.equals("no")) {


                        no="selected";
                    }
                    System.out.println(selceted);
                    getServletContext().setAttribute("id", id);
                    request.setAttribute("id", id);
                out.print("<tr><td>Username :</td><td><input id="+st+" name="+it+" value='"+rset.getString("user_details_username") +"' type="+t+">"
                        +"</td></tr><tr><td>Password :</td><td><input id="+st+" name="+pn1+"  value='"+rset.getString("user_details_password") +"' type="+p+">"
                        +"</td></tr><tr><td>Conform Password :</td><td><input id="+st+" name="+pn2+"  value='"+rset.getString("user_details_password") +"' type="+p+">"
                        +"</td></tr><tr><td>User Type:</td><td><select id="+ss+" name="+ut+" ></option><option   value="+"Admin"+" "+admin+">Admin</option><option  value="+"user"+" "+user+">User</option></select>"
                        +"</td></tr><tr><td>Auccess Permission:</td><td><select id="+ss+" name="+sn+" ></option><option   value="+sv1+" "+yes+">yes</option><option  value="+sv2+" "+no+">No</option></select>"
                        +"</td></tr>><tr><td><input class="+bs+" type="+bt1+" value="+bv1+" /></td><td><input id="+bt2+" class="+bs+" type="+bt2+" value="+bv2+" /></td></tr>");
                        out.print("</table></form>");
                        request.setAttribute("id", id);
                        con.close();

                }
                        }
             catch (SQLException e) {
                // TODO Auto-generated catch block

                System.out.println(e.toString());
            }
        }
        request.getRequestDispatcher("footer.jsp").include(request, response);
        out.close();
    }

protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String name = request.getParameter("username");
		System.out.println(name);
		String password = request.getParameter("password");
		System.out.println(password);
		String usertype = request.getParameter("usertype");
		System.out.println(usertype);
		String aucesspermission = request.getParameter("aucesspermision");
		System.out.println(aucesspermission);
		String id = request.getAttribute("id").toString();
		System.out.println(id);
		int status = UpdateUserDao.save(name, password, usertype,
				aucesspermission, id);
		if (status > 0) {
			request.getRequestDispatcher("UserAccountServlet").include(request,
					response);

		} else {

			request.getSession().setAttribute("login",
					"Please give Correct information");
			request.getRequestDispatcher("AddUserDetailServlet").include(
					request, response);
		}

		out.close();
	}


my second servlet code was
Posted
Comments
prakash firefox 17-Jul-15 3:26am    
i marked as bold letter in my code which code is not correctly working. please help me

1 solution

i marked as bold letter in my code which code is not correctly working. please help me
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900