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

2023-03-15,,

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中显示数据的相关教程结束。

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

下载本文的Word格式文档,以方便收藏与打印。