Java怎么给jsp页面赋值

互联网 19-5-29
使用转发来给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页面代码:

<%@ 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页面赋值的详细内容,更多内容请关注技术你好其它相关文章!

来源链接:
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
标签: java
上一篇:php获取远程图片并下载保存到本地的方法分析 下一篇:java数组的引用有什么意义

相关资讯