我是靠谱客的博主 顺利悟空,这篇文章主要介绍Java怎么给jsp页面赋值,现在分享给大家,希望可以做个参考。

使用转发来给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页面赋值的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是顺利悟空最近收集整理的关于Java怎么给jsp页面赋值的全部内容,更多相关Java怎么给jsp页面赋值内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(167)

评论列表共有 0 条评论

立即
投稿
返回
顶部