how to delete user form record table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vishal prada
    New Member
    • Mar 2012
    • 52

    how to delete user form record table

    Code:
    <html>
        <body>
         
        <table width="50%" border="1" rules=ALL>
        <tr><th> Username</th><th>Access Level</th><th>Delete</th></tr>
        <%@ page language="java" import="java.sql.*" %>
        <%
        int j=0;
        
        Class.forName("com.mysql.jdbc.Driver");
    	Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/registration","root","root");
    	Statement st = con.createStatement();
    	ResultSet rs = st.executeQuery("select * from regist");
        while (rs.next())
        { j=j+1;%>
        <tr><td align="center"><%=rs.getString(1)%></td><td align="center"><%=rs.getString(3)%></td><td><input type="checkbox" name="delete" value="yes"></tr>
             
        <%}
         
        %>
        <form action="deleteuser.jsp">
        <input type="hidden" name="recordcount" value="<%=j%>">
        <input type="submit" name="b1" value="Delete" >
        </table>
        </form>
        </body>
        </html>
    //above is my page1.jsp
    page and want to create deleteuser.jsp page but how it will create ?, how the values are fetch.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    I see you are still ignoring the advice of separating Java code with HTML. Good luck.

    Comment

    • vishal prada
      New Member
      • Mar 2012
      • 52

      #3
      no no that's my old page where i am created one form
      and now i want to create jsf action page for the above form.

      Comment

      • vishal prada
        New Member
        • Mar 2012
        • 52

        #4
        and sorry dear i was paste that old form and u feel i am neglect ur advice that's not my view.
        i just want to know code for deleteuser.jsp page.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Read about how to use servlets and let servlets be your controller. Submit to servlets not to other JSPs.

          Comment

          • vishal prada
            New Member
            • Mar 2012
            • 52

            #6
            i am continue trying to learn servlets but not yet succeeded do u have any web pages which easy to learn that.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              There is a free online version here :http://pdf.coreservlets.com/
              you really should not be using JSPs until you understand how servlets work.

              Comment

              • vishal prada
                New Member
                • Mar 2012
                • 52

                #8
                index.html
                Code:
                <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                <html>
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                <title>Test Form</title>
                </head>
                <body>
                	<form action="servlet1" method="post">
                		Name : <input type="text" name="userName"><br>
                		Email: <input type="text" name="email"><br>
                		<input type="submit" value="submit">
                	</form>
                
                </body>
                </html>
                and my ServletExample. java
                Code:
                package org.example02.test;
                
                import java.io.IOException;
                
                import javax.servlet.ServletException;
                import javax.servlet.http.HttpServlet;
                import javax.servlet.http.HttpServletRequest;
                import javax.servlet.http.HttpServletResponse;
                
                public class ServletExample extends HttpServlet {
                	
                		protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                				throws ServletException, IOException {
                			// TODO Auto-generated method stub
                			
                			String name = req.getParameter("userName");
                			String email = req.getParameter("email");
                			String ip = req.getRemoteAddr();
                			
                			resp.getWriter().println("<html>");
                			resp.getWriter().println("<head>");
                			resp.getWriter().println("<title>This is the response</title>");
                			resp.getWriter().println("</head>");
                			resp.getWriter().println("<body>");
                			
                			resp.getWriter().println("Your name is:" + name);
                			resp.getWriter().println("Your email is:" + email);
                			resp.getWriter().println("Your IP address is:" + ip);
                			
                			resp.getWriter().println("</body>");
                			resp.getWriter().println("</html>");
                			
                			super.doPost(req, resp);
                		}
                
                }
                and web.xml file is.
                Code:
                <?xml version="1.0" encoding="UTF-8"?>
                <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
                	<display-name>Example02</display-name>
                	
                	<servlet>
                	<servlet-name>Test2</servlet-name>
                	<servlet-class>org.example02.test.ServletExample</servlet-class>
                	</servlet>
                	
                	<servlet-mapping>
                	<servlet-name>Test2</servlet-name>
                	<url-pattern>/servlet1</url-pattern>
                	</servlet-mapping>
                		<welcome-file-list>
                		<welcome-file>index.html</welcome-file>
                		<welcome-file>index.htm</welcome-file>
                		<welcome-file>index.jsp</welcome-file>
                		<welcome-file>default.html</welcome-file>
                		<welcome-file>default.htm</welcome-file>
                		<welcome-file>default.jsp</welcome-file>
                	</welcome-file-list>
                </web-app>
                //but one error is occur
                "The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL)."

                //what this means and also i use GET method on the place of POST then also same error is coming.
                what to do ?

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Don't to super.doPost(re q, resp) and don't build the HTML in the servlet. That would be mixing Java code with HTML again. After receiving the parameters in your servlet and doing some processing just forward to a jsp that will take care of the presentation using

                  Code:
                   getServletContext().getRequestDispatcher("/examples/displayResults.jsp").forward(req, res);

                  Comment

                  • vishal prada
                    New Member
                    • Mar 2012
                    • 52

                    #10
                    where i put this now..
                    Code:
                    getServletContext().getRequestDispatcher("/examples/displayResults.jsp").forward(req, res);

                    Comment

                    • vishal prada
                      New Member
                      • Mar 2012
                      • 52

                      #11
                      and u know what ?
                      on the internet guides the like this code tutorials which show
                      the servlet with html code.
                      then how can i learn proper way ?

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        In your doPost method. Instead of super.doPost(re q, resp);
                        And don't do any of the resp.getWriter( ).println( ...;
                        Let the JSP you are forwarding to deal with the presentation not the servlet.

                        Comment

                        • vishal prada
                          New Member
                          • Mar 2012
                          • 52

                          #13
                          yahoooooooooooo ooo !
                          i got it
                          thanks dear........!

                          Comment

                          • vishal prada
                            New Member
                            • Mar 2012
                            • 52

                            #14
                            this is my first servlet program which i done well with proper code.
                            thank you very much..!

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              So now use that in your program. Every time you want to submit data to the server and do some database related processing then make the source JSP submit to a servlet. That servlet can then call normal Java classes which access the database. The servlet then sets the results as attributes and submits to a JSP to display the results.
                              That way your JSPs will be free of Java code and you have a good separation of concerns.

                              Comment

                              Working...