我想在我的远程 Apache Tomcat 服务器上上传我的 servlet 文件并想编译它。我想知道我应该将这个文件保存在哪个目录下以及如何编译它?我应该使用腻子吗?我对 Servlet 比较陌生。这是我的servlet代码:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
@WebServlet(name= "db-connect", urlPatterns="/db-connect")
public class DBConnect extends HttpServlet{
private Connection con = null;
private PreparedStatement preparedStatement = null;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://http://localhost:3307/abc?autoReconnect=true");
preparedStatement = con.prepareStatement("SELECT * FROM Person");
ResultSet rs = preparedStatement.executeQuery();
while(rs.next())
{
String email = rs.getString("email");
System.out.print(email);
System.out.println("in");
}
}
catch(Exception e)
{
}
}
我还需要对 web.xml 进行更改吗?