栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用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;    }}

希望这会帮助你。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/435706.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号