0

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.

Vedant Gandhi
  • 39
  • 1
  • 9
  • *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 Answers3

0

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

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

Ranjith Bokkala
  • 379
  • 1
  • 10
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