Why do I get 'undefined' error when I try to read session atrribute from Controller

Nishant

In controller, I have set session attribute

HttpSession session = request.getSession(); session.setAttribute("Anshu", true);

In JSP,I am trying to get value from session

<input type=hidden id=file value="${sessionScope.Anshu}" />

In JavaScript,trying to display that value..

var nish=document.getElementById("file").value; alert(nish.value);

But, when I am trying to run the code ,I am getting 'Undefined' in alert statement. Can anyone tell me whay its coming 'undefined' ? Thanks in advance ! :-)

moisrex

the problem is this: <input type=hidden id=filevalue="${sessionScope.Anshu}" />

it should be like this:

<input type="hidden" id="file" value="${sessionScope.Anshu}" />

plus in your javascript code you don't have to say .value twice. once is enough.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why do I get a compilation error when I try to have two methods with the same name and parameter type?

I am using @PathVariable from springframework. When I try to return view page name from controller, I get 404 error

why do i get exception error when i try output array

Why do I get an error for "__CrtGetFileInformationByHandleEx " when I try to compile

Why do I get an "invalid values" error when I try to access the network settings on Eclipse Mars?

Why I get error when I try to create stored procedure?

Why do I see `503 Backend Error` when I try to get a Cloud Storage service account?

Why do I get an error when I try to add a dependent task to one created by the C plugin?

Why do I get error when ifstream is creating file with string read from keyboard?

When I try to make a prediction using a tensorflow.js model I get the error: Uncaught TypeError: Cannot read property 'length' of undefined

Why Do I get an error when I try to get tkinter slider value?

Why do i get this error when I try to perform some logical operation on dataframes?

why i get "no attirubute error" when i try to call python function from c++

Why do I get this error in my logcat when I try to post JSON data?

Why do I get error when I try to alert the length of the passed array to the function?

Why do I get an error (Notice: Undefined index) when I try to echo a value from my database?

Why do I get permission denied error when I log out of the SSH session?

Why am I getting an error when I try to get a string from my table in a Jframe?

Why do I get a 'constructor is undefined` error?

Why do I get a syntax error when I try to print a nested hash that has keys containing colons?

Why do I get property of undefined error?

Why do I get a NoClassDefFound error when I try to save my test plan?

Why do I get this error when I try to load the component in VueJS?

Why do i get this error when I try installing autopep8 using pip?

Why I get error when I try to declare local variable?

Why do I get a "cannot read property of undefined" error when the data is defined?

Why do I get an error when I try to see my Text using useState?

Node js: Why do I get ```TypeError: Cannot read property 'json' of undefined``` when I call an async function from an express route?

Why do I get error when try to convert Carbon to DateTime?

TOP Ranking

HotTag

Archive