📄 addservlet.java~2~
字号:
package com.test.DB;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import com.test.DB.DBConnManager;import java.sql.*;public class AddServlet extends HttpServlet { private static final String CONTENT_TYPE = "text/html; charset=GBK"; //Initialize global variables public void init() throws ServletException { } //Process the HTTP Post request public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String email = request.getParameter("email"); if (email == null) { email = ""; } String name = request.getParameter("name"); if (name == null) { name = ""; } String content = request.getParameter("content"); if (content == null) { content = ""; } DBConnManager connManage=new DBConnManager(); Connection con=connManage.getConnection("access"); if(con==null) { System.out.println("对不起,现在数据库忙,请稍后再试"); } try{ Statement stmt=con.createStatement(); String sql = "insert into liuyan(ip,email,time,content,name) values('" + request.getRemoteHost() + "','" + email + "','" + connManage.gettime() + "','" + content + "','" + name + "')"; stmt.executeUpdate(sql); response.sendRedirect("success.jsp"); }catch(Exception e){ e.printStackTrace(); } /* response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>AddServlet</title></head>"); out.println("<body bgcolor=\"#ffffff\">"); out.println("<p>The servlet has received a POST. This is the reply.</p>"); out.println("</body></html>");*/ //rs.close(); stmt.close(); connManage.releaseConnection("access",con); } //Clean up resources public void destroy() { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -