需要的jar包是servlet-api.jar(可以从tomcat的lib中拷贝)和mysql的jdbc:mysql-connector-java-5.0.8-bin.jar web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <description> </description> <display-name>SearcherSheetServlet</display-name> <servlet-name>SearcherSheetServlet</servlet-name> <servlet-class>com.waleking.servlet.SearcherSheetServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>SearcherSheetServlet</servlet-name> <url-pattern>/SearcherSheetServlet</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app> index.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> hello world! <form action="SearcherSheetServlet"> SearcherIP:<input type="text" name="searcherIP"/> TopNum:<input type="text" name="topNum"/> IndexerPort:<input type="text" name="indexerPort"/> <input type="submit"></input> </form> </body> </html> package com.waleking.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.waleking.property.db.Searcher_PropertyDAO; import com.waleking.property.db.Searcher_PropertyVO; /** * Servlet implementation class SearcherSheet */ public class SearcherSheetServlet extends HttpServlet { private static final long serialVersionUID = 1L; private Searcher_PropertyDAO searcherDAO=new Searcher_PropertyDAO(); private Searcher_PropertyVO searcherProperty=new Searcher_PropertyVO(); /** * Default constructor. */ public SearcherSheetServlet() { // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("ok"); String searcherIP=request.getParameter("searcherIP"); String topNum=request.getParameter("topNum"); System.out.println(topNum); String indexerPort=request.getParameter("indexerPort"); System.out.println(indexerPort); searcherProperty.setSearcherIP(searcherIP); searcherProperty.setTopNum(Integer.parseInt(topNum)); searcherProperty.setIndexerPort(Integer.parseInt(indexerPort)); System.out.println(searcherProperty); searcherDAO.insert(searcherProperty); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } }