首页 > Web开发 > 详细

Web_Servlet和jsp页面数据交互,通过请求转发在jsp中显示数据

时间:2020-06-28 12:41:36      阅读:129      评论:0      收藏:0      [点我收藏+]

1.Servlet页面代码

/*
    实现jsp页面和sevlet页面的信息交互
 */
@WebServlet(urlPatterns = "/aa")
public class JspService extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //以键值对存储数据

        request.setAttribute("name","张三丰");

        //进行页面跳转,把信息传过去
        request.getRequestDispatcher("/demojsp.jsp").forward(request,response);

    }
}

2.Jsp页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <div>
        <font color="#808080"><%=request.getAttribute("name")%></font>
    </div>
</body>
</html>

 

Web_Servlet和jsp页面数据交互,通过请求转发在jsp中显示数据

原文:https://www.cnblogs.com/LVowe/p/13202083.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!