How to share data between a JSP and servlet [duplicate]

旧巷老猫 提交于 2021-01-29 15:00:32

问题


I am developing a website with servlets and JSP.I want to know how to share data between a servlet and JSP as while searching I noticed that the getSession() method has been deprecated and currently I cannot add data to session for sharing the data.Please someone suggest me how should I share data between the servlets and JSP.


回答1:


We can apply two ways most probably

1 ) request
2 ) session

Examples :

request.setAttribute("userName", userName );
session.setAttribute("userName", userName );



回答2:


please follow the below references.This will help ful to you

how-do-i-share-data-between-a-jsp-page-and-servlet




回答3:


in your body method doGet do something like that,

String value = "par1"
request.setAttribute("parameter", value);

your jsp file:

<%
 String value= (String) request.getAttribute("parameter");
 out.println(value);
 %>


来源:https://stackoverflow.com/questions/60518878/how-to-share-data-between-a-jsp-and-servlet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!