Web_Servlet和jsp页面数据交互,通过请求转发在jsp中显示数据
Posted lvowe
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Web_Servlet和jsp页面数据交互,通过请求转发在jsp中显示数据相关的知识,希望对你有一定的参考价值。
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中显示数据的主要内容,如果未能解决你的问题,请参考以下文章