handlemodify.java

来自「纯粹jsp的留言板,使用了mvc」· Java 代码 · 共 58 行

JAVA
58
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package messagepad.servlets;import messagepad.beans.*;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;/** * * @author Administrator */public class handleModify extends HttpServlet{    public void init(ServletConfig config) throws ServletException{        super.init(config);        try{            Class.forName("com.mysql.jdbc.Driver");        }        catch(Exception e){        }    }    public void doPost(HttpServletRequest request,HttpServletResponse response)            throws ServletException,IOException{            Connection con;            Statement sql;            ResultSet rs;            try{                String url="jdbc:mysql://localhost/taotao";                String user="taotao";                String password=".nothing";                con=DriverManager.getConnection(url,user,password);                String strId=request.getParameter("tomod");                int tt=Integer.parseInt(strId);                //byte b[]=str.getBytes("UTF-8");                //str=new String(b);                String strNewcontent=request.getParameter("newcontent");                //byte b[]=strContent.getBytes("UTF-8");                //strContent=new String(b);                String updateCondition="update messages set content="+"'"+strNewcontent+"'"+" where number = "+tt;                sql=con.createStatement();                sql.executeUpdate(updateCondition);            }            catch(SQLException e){            }            //response.encodeRedirectURL("index.jsp");            RequestDispatcher dispatcher=request.getRequestDispatcher("helpReadRecord");            dispatcher.forward(request, response);    }    public void doGet(HttpServletRequest request,HttpServletResponse response)            throws ServletException,IOException{            doPost(request,response);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?