I am in need of some assistance. I do not understand this assignment. Please pla
ID: 645021 • Letter: I
Question
I am in need of some assistance. I do not understand this assignment. Please place some comments in your code to help me understand what is goind on. I think I have some of the basics down. I will award max points for your answer.
Assignment
Create a new Web application titled Week5. In this application you will also create a virtual directory so that you do not have to use the word servlet as part of your form post URL. You will then be able to run your Web application servlet by using a URL similar to the following: http://localhost:7070/Week5/FormPost2. To create your virtual directory you may start by modifying the web.xml attached to this assignment. Next, create a Servlet 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 servlet, which in the doPost method will save the form data to a database. You may use an existing table or create your own new table. If a new table is created, please include your create script in the zip. Whichever table you use, make sure that it has at least three fields and your form allows input for each field. 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 servlet FormPost2 and name the application Week5. Create a Web archive file and attach to this assignment. Do not copy (cut and paste) any example code, create your own code and use the examples as a guide.
For all assignments connecting to a DBMS you will need to use the following account ID and password:
Account ID: student1
Password: pass
Explanation / Answer
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import oracle.jdbc.OracleResultSetMetaData;
public class CreateTable extends HttpServlet{
private String target = "localhost:7070/examples/servlet/CreateTable";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
PrintWriter out = response.getWriter();
Connection con = null;
Statement stmt = null;
printHeader(out);
try{
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
con = DriverManager.getConnection("jdbc:oracle://localhost;"+ "account_id=student1;password=pass");
stmt = con.createStatement();
}
catch(Exception e){
out.println(" Error in connecting database.");
printFooter(out);
return;
}
try{
stmt.executeUpdate("DROP TABLE Wins_Servlet");
out.println("Table Dropped");
}
catch(SQLException e){out.println("Table does not exist");}
try{
stmt.executeUpdate("CREATE TABLE Wins_Servlet(Team CHAR(20) NOT NULL, City CHAR(20) NOT NULL, Year_T INT NOT NULL PRIMARY KEY, LoserTeam CHAR(20) NOT NULL, LoserCity CHAR(20) NOT NULL)");
out.println("Table Created ");
}
catch(SQLException e){ out.println("Table Creation failed ");
}
try{
stmt.close();
con.close();
out.println("Database connections closed");
}
catch(SQLException e){out.println("Connection close failed ");}
printFooter(out);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
PrintWriter out = response.getWriter();
printHeader(out);
out.println("Not authorized to view this page. ");
printFooter(out);
}
public void printHeader(PrintWriter out){
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
}
public void printFooter(PrintWriter out){
out.println("");
out.println("");
out.println("");
}
}
//table Wins_Servlet created
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.