势必拿下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条)

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示