Submit html form to a Servlet

Asked

Viewed 258 times

0

I made a connection with mysql and I’m making a crud on its own java. I want to use html and send to java to do the crud. From what I read, you need a servlet. I tried to do it, but I couldn’t. They follow the codes:

connection class:

package conect_DB;  

import java.sql.DriverManager;  
import java.sql.SQLException;  

public class Conexao {  

    public static java.sql.Connection conexao;  
    private static String servidor = "jdbc:mysql://localhost:3306/ucsal";  

    public static boolean conectar() {  
    try {  

        Class driverMysql = Class.forName("com.mysql.jdbc.Driver");  

        conexao = DriverManager.getConnection(servidor, "root", "");  

        if (conexao == null) {  
        return false;  
        }  
    }  

    catch (ClassNotFoundException e) {  
        System.out.println(e.getMessage() + " on method 'conectar' error");  
    }  

    catch (SQLException e) {  
        System.out.println(e.getMessage());  
    }  

    return true;  
    }  

    public static void desconectar() {  
    try {  
        conexao.close();  
    }  

    catch (SQLException e) {  
        System.out.println(e.getMessage());  
    }  

    catch (NullPointerException e) {  
        System.out.println("method 'close()' error. Not conection opened");  
    }  
    }  

}  

Servlet (format Obs .java. Seria .jsp?)

package servlets;  

public class Server {  


}  

The tag of the form:

<form name="form1" method="POST" action="Server">

//formulario aqui

</form>

How would this passage to the servlet? I don’t know how to do the xml.

  • @rray this link may serve me, but before I get there, I need to know a few things, like: do I need the xml? If I pass the name of Servlet in the form, then I can already crud without xml? If so, I can use that link. If not, I need to structure the xml and then use this link.

  • you use Servlet 3? from this version an annotation already serves, from the account you need to configure the web.xml.

  • @rray do not know if I can understand the version of Servlet. No eclipse, if I’m not mistaken, has the new > Servlet. When I tried to send the form to Servlet, I created a.javar file. So I don’t know how to create Servlet.

  • Look at this answer tries to put the annotations http://stackoverflow.com/a/18187372/1342547

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.