I have a question with servlets

0

Hello, this is my code that I have but I do not know how this would happen, I have a servlet truth I have no idea and I am suffering if someone can help me I will thank you, by the way I already have what is the connection and that I only need the servelet

 public void   Modifica (int estado, java.util.Date fechaHora,  java.util.Date fechaHoraultima, int id_publicacion)               
 {
  Connection connection = null;
  PreparedStatement prepareStmt = null;

  String query = "update publicaciones set estado,"
        + "fechaHora=?, "
        + "fechaHoraultima=GETDATE() "
        + "where id_publicacion = ? ";

  try{
      connection = getDBConnection();
      prepareStmt  = connection.prepareStatement(query);


      prepareStmt.setInt(1,estado);
      prepareStmt.setDate(2,fechaHora);
      prepareStmt.setDate(3,fechaHoraultima );
      prepareStmt.setInt(4,id_publicacion);
      prepareStmt.executeUpdate();

  } catch (SQLException e) {
      System.out.println(e.getMessage());
  }
  }
    
asked by NymHaRI 16.08.2017 в 17:54
source

1 answer

0

Servlets are a class that extends from HttpServlet .

This class uses two main methods to process the request: doGet and doPost.

If your code already works then it is simply to paste it into one of those methods which will be executed according to your request. For example, if it's from an HTML form and you want the doPost method to run, you have to set POST in the method attribute of the form.

The response of the servlets varies according to how you want to use it (a response string, a redirect, a formatted message), see the documentation .

Here's a simple example

To be able to use a servlet you have to register it on the web .xml of your project.:

<web-app>
  <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>servletexample.createHelloWorldExample
      </servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>/HelloWorldExample/*</url-pattern>
  </servlet-mapping>
</web-app>
    
answered by 16.08.2017 в 18:07