势必拿下SpringBoot 2021-06-03 19:58 采纳率: 100%
浏览 74
已采纳

Servlet运行没有报错但是数据库添加失败了

 

package Servlet;

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

import Information.CusInformation;
import dao.CusDao;
import dao.CusDaoImpl;


@WebServlet("/CusServlet")
public class CusServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        System.out.println("登陆成功");
        String name=request.getParameter("name");
        String password=request.getParameter("password");
        String idendity=request.getParameter("idendity");
        CusInformation cusinfor=new CusInformation();
        cusinfor.setName(name);
        cusinfor.setPassword(password);
        cusinfor.setIdendity(idendity);
        
        CusDao cd=new CusDaoImpl();
        if(name!=""&&password!="")
        try {
            cd.add(cusinfor);
            
        
        }catch(Exception e){
            System.out.println("fail");
            e.printStackTrace();
        }
        else {
            System.out.println("您的账户或密码不能为空");
        }
        
        
        
        }
        
    }


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="cusServlet" method="post">
请输入您的账号:<input type="text" name="name"><br>
请输入您的密码:<input type="text" name="password"><br>
请选着您的身份:<select name="identity">
<option value="0">管理员</option>
<option value="1">顾客</option>
</select>
<input type="submit" value="登录">
<input type="reset" value="重置">
</form>
</body>
</html>

  • 写回答

4条回答 默认 最新

  • CSDN专家-sinJack 2021-06-03 19:59
    关注

    这后台不是报错了吗,看下是不是sql写错了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择