Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a new Web application titled <yourname>Week7. Next, create a JSP that dis

ID: 3624427 • Letter: C

Question

Create a new Web application titled <yourname>Week7. Next, create a JSP that displays a form when the doGet method is invoked. The form will contain a post action that directs the form post back to the same JSP, which in the doPost method will save the form data to a database using a Java Bean. Use your Oracle account to make the DB connection. After the form data has been saved to the database, respond back with a query from the database displaying all the current records contained in the database, in an appealing format. The form must contain a minimum of three input fields. The grade for this assignment will be based both on the functionality of the servlet and the appearance of the form post results. Name your JSP <yourName>FormPost4 and name the application <yourname>Week7. Create a Web archive file and attach to this assignment.

Explanation / Answer

Dear... Save the html file into .jsp fomate.
<html> <body> <%@ page import="java.util.*" %> <jsp:useBean id="formPost" class="com.beans.<yourname>FormPost4"> <jsp:setProperty name="formPost" property="fName" param="FNAME" /> <jsp:setProperty name="formPost" property="lName" param="LNAME" /> <jsp:setProperty name="formPost" property="phone" param="PHONE" /> </jsp:useBean> <% formPost.init(); %> <% if(request.getMethod().equals("GET")) { %> <form action='<%=request.getRequestURI()%>' method='post' > First Name: <input type='text' name='FNAME' /><br> Last Name: <input type='text' name='LNAME' /><br> Phone: <input type='text' name='PHONE' /> <input type='submit' value='Submit' /> </form> <% } if(request.getMethod().equals("POST"))
{     try
   {       List<Vector<String>> rset = formPost.saveAndLoadUsers();       for(int i=0; i<rset.size(); i++)
       {          Vector<String> row = rset.get(i);        %> <pre>First Name: <%=row.get(1) %></pre> <pre>Last Name: <%=rset.get(2)%></pre> <pre>Phone: <%=rset.get(3)%></pre><br> <% } } catch (Exception e)
{         out.println(e.getMessage()); } } %> </body> </html> java bean:
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import java.util.Vector; public class <yourname>FormPost4 {                private Connection con = null;                private String fName;                private String lName;                private String phone;                public String getfName()                 {                                return fName;                }                 public void setfName(String fName)                 {                                this.fName = fName;                }                public String getlName()                 {                                return lName;                }                public void setlName(String lName)                 {                                this.lName = lName;                }                 public String getPhone()                 {                                return phone;                }                public void setPhone(String phone)                 {                                this.phone = phone;                }                public void init()                 {                      try                              {                              Class.forName ("oracle.jdbc.driver.OracleDriver");                              con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",                                                                                                                                 "student1", "pass");                              Statement stmt = con.createStatement();                              stmt.executeUpdate("CREATE TABLE MYTABLE (FNAME VARCHAR2(20),
                                                                    LNAME VARCHAR2(40), PHONE VARCHAR2(20))");                              stmt.close();                              }                             catch (Exception e)                              {                                  }                }               public List<Vector<String>> saveAndLoadUsers() throws SQLException               {                  if(con == null)                  {                    init();                   }                 Statement stmt = con.createStatement();                 stmt.executeUpdate("INSERT INTO MYTABLE VALUES                    ('" + this.fName + "', '" + this.lName + "', '" + this.phone + "')");                 List<Vector<String>> result = new ArrayList<Vector<String>>();                 Vector<String> row = new Vector<String>();                 ResultSet rset = stmt.executeQuery("SELECT * from MYTABLE");                 while (rset.next())                  {                   row.add(rset.getString(1));                   row.add(rset.getString(2));                   row.add(rset.getString(3));                   result.add(row);                  }                  stmt.close();                  return result;               } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote