这个在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页面代码:
<%@ 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>页面代码</title> </head> <body> <h5>通过request对象取值</h5> 账号:<%=request.getAttribute("username") %> 密码:<%=request.getAttribute("password") %> <P>=======================</P> <h5>通过EL表达式取值</h5> 账号:${username} 密码:${password} </body> </html>
以上就是Java怎么给jsp页面赋值的详细内容,更多请关注大盘站其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。