日期:2014-05-17 浏览次数:20803 次
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { try { PrintWriter out = response.getWriter(); response.setContentType("text/html;charset=gb2312"); out.println("<HTML>"); out.println("<BODY>"); out.println("<a href='mainpage.jsp'>返回</a>"); out.println("</BODY>"); out.println("</HTML>"); DBBean dbbean = new DBBean(); request.setCharacterEncoding("utf-8"); String insert = "insert into news(num,theme,author,date) values('" + request.getParameter("num") + "','" + request.getParameter("theme") + "','" + request.getParameter("author") + "','" + request.getParameter("date") + "')"; if (null != request.getParameter("num")&& !"".equals(request.getParameter("num"))) { dbbean.update(insert); } } catch (Exception ex) { ex.printStackTrace(); } finally { DBBean dbbean = new DBBean(); dbbean.close(); } } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } }
<form onSubmit="return validate()" method="post" name="biaoge" action="servlet/MyServlet" ><br> 编号:<input type="text" name="num" ><br> <br> 主题:<input type="text" name="theme" ><br> <br> 作者:<input type="text" name="author" ><br> <br> 日期:<input type="text" name="date" ><br> <br> <input type="submit" value=提交></form>