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

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 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd