加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
UserServlet.java 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
Your Name 提交于 2020-12-12 17:31 . 团队项目1
package webDemo101;
import java.io.IOException;
import java.sql.SQLException;
import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/userServlet")
public class UserServlet extends HttpServlet {
private UserDao userDao = new UserDao();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
int age = Integer.parseInt(req.getParameter("age"));
int phone =Integer.parseInt(req.getParameter("phone"));
User user =new User ();
user.setAge(age);
user.setName(name);
user.setPhone(phone);
try {
userDao.insertUser(user);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化