Попытка обновить информацию на странице сервлета.Но получите ответ HTTP 404 (apache tomcat).
Не знаю, в чем проблема
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Update extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
PrintWriter out = res.getWriter();
{
res.setContentType("text/html");
out.println("<html>");
out.println("<head>");
out.println("<title>");
out.println("Update Page");
out.println("</title>");
out.println("</head>");
out.println("<body>");
out.println("<table>");
Connection connection = null;
Statement statement = null;
ResultSet resultset = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/userdb";
DriverManager.getConnection(url,"root","root123");
connection = DriverManager.getConnection(url,"root","root123");
statement = connection.createStatement();
System.out.println("Database Successfully Connected");
resultset = statement.executeQuery("select * from user_table");
while(resultset.next())
{
out.println("<form action='update' method='post'>");
out.println("<tr>");
out.println("<td>");
out.println("<input type='text' name='name' value='" + resultset.getString(1) +"' / >");
out.println("<td>");
out.println("<input type='text' name='age' value='" + resultset.getString(2) +"' / >");
out.println("<td>");
out.println("<input type='text' name='height' value='" + resultset.getString(3) +"' / >");
out.println("<td>");
out.println("<input type='text' name='weight' value='" + resultset.getString(4) +"' / >");
out.println("<td>");
out.println("<input type='submit' value='Update' / >");
out.println("</form>");
}
}
catch(ClassNotFoundException ce)
{
out.println("Error " + ce);
}
catch(SQLException se)
{
out.println("Error " + se);
}
finally
{
try
{
connection.close();
}
catch(Exception e)
{
}
}
out.println("</table>");
out.println("</body>");
out.println("</html>");
}
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>");
out.println("Select Page");
out.println("</title>");
out.println("</head>");
out.println("<body>");
Connection connection = null;
Statement statement = null;
String name = req.getParameter("name");
String age = req.getParameter("age");
String height = req.getParameter("height");
String weight = req.getParameter("weight");
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/userdb";
connection = DriverManager.getConnection(url,"root","root123");
statement = connection.createStatement();
String query = "update user_table set age='" + age + "', height='" + height + "', weight='" + weight + "' where name='" + name + "'";
int result = statement.executeUpdate(query);
out.println(result + " row(s) updated.");
}
catch(ClassNotFoundException ce)
{
out.println("Error " + ce);
}
catch(SQLException se)
{
out.println("Error " + se);
}
finally
{
try
{
connection.close();
}
catch(Exception e)
{
}
}
out.println("</body>");
out.println("</html>");
}
}
Кнопка обновления должна направлять на страницу, на которой указаны 1 обновленные строки.Я думаю, что это часть запроса или часть объявления.Там нет ничего плохого, когда компилировать просто результат просто нет, как ожидалось.Надеюсь, что кто-нибудь поможет с проблемой