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.
Asked
Active
Viewed 408 times
0
-
*the getSession() method has been deprecated*. [This is not true](https://jakarta.ee/specifications/platform/8/apidocs/javax/servlet/http/HttpServletRequest.html#getSession--). So either you looked up the wrong documentation, or someone on the internet has lied without posting any reference links and you haven't looked up the documentation to confirm for yourself, or your understanding of the meaning of "deprecated" is wrong. – BalusC Mar 04 '20 at 09:29
-
Ok I might have used up wrong resource thanks for your help – Vedant Gandhi Mar 06 '20 at 07:38
3 Answers
0
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);
%>

tino89
- 142
- 5
0
We can apply two ways most probably
1 ) request
2 ) session
Examples :
request.setAttribute("userName", userName );
session.setAttribute("userName", userName );

Lova Chittumuri
- 2,994
- 1
- 30
- 33
-
this is more way good and now i am able to set attributes as per the requirements.Thank you for helping me – Vedant Gandhi Mar 06 '20 at 07:39
-
@vedantGandhi try to keep post the question by follow some protocals refer this https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/ – Lova Chittumuri Mar 06 '20 at 07:45
-
-