日期:2014-05-17 浏览次数:20829 次
package zgl.test.client; import java.io.IOException; import java.util.Date; //import java.sql.Date; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import zgl.test.bean.Cat; /** * Servlet implementation class HelloWorld */ public class HelloWorld extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public HelloWorld() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); java.io.PrintWriter out = response.getWriter(); out.println("--------------你好吗?--------------"); Cat cat=new Cat(); cat.setBirth(new Date()); cat.setCatname("迷人的天空"); zgl.test.util.HibernateUtil.addCat(cat); if (out != null) out.close(); } }
package zgl.test.client; import java.util.Date; import javax.servlet.ServletException; import zgl.test.bean.Cat; public class Test { /** * @param args * @throws ServletException */ public static void main(String[] args) throws ServletException { //为什么会初始化失败呢,为什么获取配置为空指针呢? Cat cat=new Cat(); cat.setBirth(new Date()); cat.setCatname("迷人的天空"); zgl.test.util.HibernateUtil.addCat(cat); } }