Note: For an expert only, please! Create a new Web application titled <yourname>
ID: 3624594 • Letter: N
Question
Note: For an expert only, please!Create a new Web application titled <yourname>Week8. 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 and a Custom Tag. 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>FormPost5 and name the application <yourname>Week8. Create a Web archive file and attach to this assignment.
Explanation / Answer
Dear user,
Here is the code below:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class FormPost5 extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res) throws
IOException, ServletException
{
res.setContentType("text/html");
String sn = req.getParameter("studentname");
String fn= req.getParameter("fathername");
String dbo = req.getParameter("dbo");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbc");
Connection co =DriverManager.getConnection("jdbc:odbc:dsn","system","manager");
String sql="insert into data(sname,fname,dob)values(?,?,?)";
PreparedStatement p=co.prepareStatement(sql);
p.setString(1,sn);
p.setString(2,fn);
p.setString(3,dbo);
p.executeUpdate();
co.commit();
res.sendRedirect("Week8.html");
}
catch (Exception e)
{
System.out.println(e);
}
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws
IOException, ServletException
{
doPost (req,res);
}
}
DB:
CREATE TABLE "DATA"
( "SNAME" VARCHAR2(4000),
"FNAME" VARCHAR2(4000),
"DOB" VARCHAR2(4000)
)
Web-XML
<web-app>
<welcome-file-list>
<welcome-file>Week8.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>FormPost5</servlet-name>
<servlet-class>FormPost5</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FormPost5</servlet-name>
<url-pattern>/FormPost5</url-pattern>
</servlet-mapping>
</web-app>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.