使用DAO将值从Java类传递到jsp页面

使用DAO将值从Java类传递到jsp页面,第1张

使用DAO将值从Java类传递到jsp页面

您需要像下面这样从servlet调用DAO方法

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {      // call DAO method to get the email and password    HashMap<String,String> map=ViewDAO.getDetails();    //from the map you will get the  email and password.then you need to set them in the attributes and get them in your jsp     request.setAttribute("email", map.get("email"));      request.setAttribute("password", map.get("password"));}

您的DAO方法应如下所示:

public static HashMap<String,String>  getDetails(user u) {    Connection con=ConnectionProvider.getCon();     String uname=u.getUname();    Map<String,String> map=new HashMap<>();    try {        PreparedStatement ps=con.prepareStatement("select email,pass from  S1.USER432 where name='"+uname+"'");        ResultSet rs = ps.executeQuery();        while (rs.next()) { String email = rs.getString("EMAIL"); String pass = rs.getString("PASS"); }       map.put("email",email);       map.put("password",pass);    } catch (SQLException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }return map;    }}

希望这会帮助你。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5123750.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存