使用转发来给jsp页面赋值。具体操作如下:
这个在servlet中可是使用转发实现参数传递
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("UTF-8"); request.setAttribute("username", "dhweicheng"); request.setAttribute("password", "123456"); request.getRequestDispatcher("/my.jsp").forward(request, response); }
jsp页面代码:
nbsp;html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <meta> <title>页面代码</title> <h5>通过request对象取值</h5> 账号: 密码: <p>=======================</p> <h5>通过EL表达式取值</h5> 账号:${username} 密码:${password}
以上就是Java怎么给jsp页面赋值的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2024 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号