servlet传送数据给jsp页面

时间:2023-02-06 19:40:21

-----------------------------------------------------------------------------------------------------------------------------------------------------

在servlet中如果你像下面这样传送数据给JSP页面是不行的:

request.setAttribute("user", "123456");

----------------------------------------------------------------------------------

解决方法:

                                       用application对象来传送数据即可

 

1.servlet主要代码如下:

this.getServletContext().setAttribute("user","123456");

 

2.jsp页面接收代码如下:

<center>
          <%=application.getAttribute("user") %><br>
 </center>

-------------------------------------------------------------------------------