• 大小: 1.85MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-15
  • 语言: Java
  • 标签: javaweb  

资源简介

Javaweb的增删改查的小案例(jsp+tomcat+eclipse+mysql)

资源截图

代码片段和文件信息

package jdb1;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AddMyPersonServlet
 */
@WebServlet(“/AddMyPersonServlet“)
public class AddMyPersonServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddMyPersonServlet() {
        super();
        // 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

request.setCharacterEncoding(“UTF-8“);

String stuNum = request.getParameter(“stuNum“);

String stuName = request.getParameter(“stuName“);

String stuSex = request.getParameter(“stuSex“);

String stuAge = request.getParameter(“stuAge“);

String stuAddr = request.getParameter(“stuAddr“);

        try {

Class.forName(“com.mysql.cj.jdbc.Driver“);

String url = “jdbc:mysql://localhost:3306/itcast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=true“;

String user = “root“;

String pass = “123456“;

Connection conn = DriverManager.getConnection(urluserpass);

String sql = “insert into studInfo(stuNumstuNamestuSexstuAgestuAddr) values(?????)“;

PreparedStatement ps  = conn.prepareStatement(sql);

    ps.setInt(1 Integer.parseInt(stuNum));
    
            ps.setString(2 stuName);
    
    ps.setString(3 stuSex);
    
    ps.setInt(4 Integer.parseInt(stuAge));
    
    ps.setString(5 stuAddr);
    
int result = ps.executeUpdate();

response.sendRedirect(“FindMyPersonServlet“);

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
// TODO Auto-generated method stub
doGet(request response);
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-06-11 22:57  jdb1\
     文件        1040  2018-06-11 22:58  jdb1\.classpath
     文件         904  2018-06-11 22:57  jdb1\.project
     目录           0  2018-06-11 22:57  jdb1\.settings\
     文件         567  2018-06-11 22:57  jdb1\.settings\.jsdtscope
     文件         670  2018-06-11 22:58  jdb1\.settings\org.eclipse.jdt.core.prefs
     文件         464  2018-06-11 22:57  jdb1\.settings\org.eclipse.wst.common.component
     文件         331  2018-06-11 22:57  jdb1\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2018-06-11 22:57  jdb1\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2018-06-11 22:57  jdb1\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2018-06-14 22:09  jdb1\WebContent\
     文件         788  2018-06-14 23:11  jdb1\WebContent\AddMyPerson.jsp
     文件         774  2018-06-11 23:05  jdb1\WebContent\Login.jsp
     目录           0  2018-06-11 22:57  jdb1\WebContent\meta-INF\
     文件          39  2018-06-11 22:57  jdb1\WebContent\meta-INF\MANIFEST.MF
     文件         994  2018-06-14 21:15  jdb1\WebContent\ShowMyPerson.jsp
     文件        1748  2018-06-14 22:02  jdb1\WebContent\ShowMyPersons.jsp
     目录           0  2018-06-14 22:10  jdb1\WebContent\WEB-INF\
     目录           0  2018-06-11 23:44  jdb1\WebContent\WEB-INF\lib\
     文件     2036609  2018-06-11 23:44  jdb1\WebContent\WEB-INF\lib\mysql-connector-java-8.0.11.jar
     目录           0  2018-06-11 22:57  jdb1\build\
     目录           0  2018-07-19 08:41  jdb1\build\classes\
     目录           0  2018-07-19 08:41  jdb1\build\classes\jdb1\
     文件        2771  2018-07-19 08:41  jdb1\build\classes\jdb1\AddMyPersonServlet.class
     文件        2443  2018-07-19 08:41  jdb1\build\classes\jdb1\DeleteMyPersonServlet.class
     文件        3235  2018-07-19 08:41  jdb1\build\classes\jdb1\FUpdateMyPersonServlet.class
     文件        3423  2018-07-19 08:41  jdb1\build\classes\jdb1\FindMyPersonServlet.class
     文件        2650  2018-07-19 08:41  jdb1\build\classes\jdb1\LoginServlet.class
     文件        1344  2018-07-19 08:41  jdb1\build\classes\jdb1\MyPerson.class
     文件        2800  2018-07-19 08:41  jdb1\build\classes\jdb1\UpdateMyPersonServlet.class
     目录           0  2018-06-11 23:00  jdb1\src\
............此处省略8个文件信息

评论

共有 条评论