0

session.jsp Created a jsp file and Started and Setted the session attributes.

session=request.getSession();
session.setAttribute("eid", Employee_Id);
session.setAttribute("Employee_name", rs.getString(2));

Getsession.jsp In this file i am getting the session attribute Employee_name by using.

<% 
String name=(String)session.getAttribute("Employee_name"); 
out.print(name); 
%> 

Getsession.js In this js file i am trying to get the session attribute eid which i need to pass to ajax call to fetch image file.

But I am not getting the value that i required.

function GetImg() 
{
    
    var value = `<% session.getAttribute("eid"); %>`;

    alert(value);
}

Result i am getting is an alert message like this @Request.RequestContext.HttpContext.Session["eid"]'

i am not getting eid value.

chethan
  • 33
  • 4
  • Does this answer your question? [Read session variable in javascript?](https://stackoverflow.com/questions/18009370/read-session-variable-in-javascript) – Swati Jun 22 '20 at 12:47
  • @Swati answer did not solve my problem. i am getting like, (logic: var value = '<%= session.getAttribute("uid") %>'; ). Instead of getting uid value i am getting <%= session.getAttribute("uid") %> as output. – chethan Jun 24 '20 at 09:23
  • According to your code provided it should be `eid` instead of `uid` ? – Swati Jun 24 '20 at 13:32
  • @Swati sorry it is eid, but it is also not working, i am getting full line as output value instead of eid value. – chethan Jun 27 '20 at 11:18
  • why don't you pass the session value as `parameter` to your `GetImg()` ? – Swati Jun 27 '20 at 13:59
  • @Swati i am using jsp and sql as i said, i am trying to fetch the session attribute which i set when a user login . now i need that id attribute to fetch the user image from the sql database. but i am not getting the session attributes in javascript file. if you have idea give me a example. – chethan Jun 28 '20 at 12:45
  • from where does `GetImg() ` function get called ? can show that as well ? – Swati Jun 28 '20 at 12:50
  • @Swati i am using Ajax call for getting User Image – chethan Jul 02 '20 at 16:24
  • ti call that i need User Login Id which i am storing in session as Attributes – chethan Jul 02 '20 at 16:25
  • @Swati Or if you know any other way to get image from sql where image is in blob format and i need to fetch image using login user_id. give me some example using JSP, JS, MsSQL etc. – chethan Jul 09 '20 at 07:21
  • You can check [this](https://stackoverflow.com/questions/2340406/how-to-retrieve-and-display-images-from-a-database-in-a-jsp-page) post for doing same. – Swati Jul 09 '20 at 12:26

0 Answers0