1010day-人口普查系统
1、xiugai.java
package com.edu.ia;
import java.io.IOException;
import java.sql.SQLException;
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 xiugai
*/
@WebServlet("/xiugai")
public class xiugai extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String name=request.getSession().getAttribute("name").toString();
String ID=request.getParameter("ID");
String sex=request.getParameter("sex");
String nation=request.getParameter("nation");
String educator=request.getParameter("educator");
hand L=new hand();
try {
L.update(name, ID, sex, nation, educator);
request.getRequestDispatcher("jieguo.jsp").forward(request, response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
2、shanchu.java
package com.edu.ia;
import java.io.IOException;
import java.sql.SQLException;
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 shanchu
*/
@WebServlet("/shanchu")
public class shanchu extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String name=request.getParameter("name");
hand L=new hand();
try {
L.delete(name);
request.getRequestDispatcher("getResult.jsp").forward(request, response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
3、People.java
package com.edu.ia;
import java.io.IOException;
import java.sql.SQLException;
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 People
*/
@WebServlet("/People")
public class People extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String hubie=request.getParameter("hubie");
String zhufang=request.getParameter("zhufang");
String mianji=request.getParameter("mianji");
String fangjianshu=request.getParameter("fangjianshu");
String name=request.getParameter("name");
String ID=request.getParameter("ID");
String sex=request.getParameter("sex");
String nation=request.getParameter("nation");
String educator=request.getParameter("educator");
get login=new get(hubie,zhufang,mianji,fangjianshu,name,ID,sex,nation,educator);
hand L=new hand();
try {
L.insert(login);
request.getRequestDispatcher("Browse.jsp").forward(request, response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
4、hand.java
package com.edu.ia;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class hand {
public void insert(get L) throws SQLException {
String sql = "insert into test(hubie,zhufang,mianji,fangjianshu,name,ID,sex,nation,educator)values(?,?,?,?,?,?,?,?,?)";
Connection connection = DBUtil.getConnection();
PreparedStatement preparedStatement = null;
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1,L.getHubie());
preparedStatement.setString(2,L.getZhufang());
preparedStatement.setString(3,L.getMianji());
preparedStatement.setString(4,L.getFangjianshu());
preparedStatement.setString(5,L.getName());
preparedStatement.setString(6,L.getID());
preparedStatement.setString(7,L.getSex());
preparedStatement.setString(8,L.getNation());
preparedStatement.setString(9,L.getEducator());
preparedStatement.execute();
}
public void update(String name,String ID,String sex,String nation,String educator) throws SQLException {
String sql="UPDATE test SET ID=?,sex=?,nation=?,educator=? where name=?";
Connection conn= DBUtil.getConnection();
PreparedStatement papre=conn.prepareStatement(sql);
papre.setString(1, ID);
papre.setString(2, sex);
papre.setString(3, nation);
papre.setString(4, educator);
papre.setString(5, name);
papre.execute();
}
public void delete(String name) throws SQLException {
String sql="delete from test where name=?";
Connection conn= DBUtil.getConnection();
PreparedStatement papre=conn.prepareStatement(sql);
papre.setNString(1, name);
papre.execute();
}
}
5、get.java
package com.edu.ia;
public class get {
String hubie;
String zhufang;
String mianji;
String fangjianshu;
String name;
String ID;
String sex;
String nation;
String educator;
public String getHubie() {
return hubie;
}
public void setHubie(String hubie) {
this.hubie = hubie;
}
public String getZhufang() {
return zhufang;
}
public void setZhufang(String zhufang) {
this.zhufang = zhufang;
}
public String getMianji() {
return mianji;
}
public void setMianji(String mianji) {
this.mianji = mianji;
}
public String getFangjianshu() {
return fangjianshu;
}
public void setFangjianshu(String fnagjianshu) {
this.fangjianshu = fnagjianshu;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getNation() {
return nation;
}
public void setNation(String nation) {
this.nation = nation;
}
public String getEducator() {
return educator;
}
public void setEducator(String educator) {
this.educator = educator;
}
public get(String a,String b,String c,String d,String e,String f,String h,String g,String n) {
hubie=a;
zhufang=b;
mianji=c;
fangjianshu=d;
name=e;
ID=f;
sex=h;
nation=g;
educator=n;
}
}
__EOF__

本文链接:https://www.cnblogs.com/lx06/p/14165066.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类