0

Is this possible that i do request.setAttribute in jsp code and retrive the value using request.getAttribute in java struts code.

3
  • What happened when you tried it? Commented Aug 1, 2011 at 11:10
  • I debugged and i got null value. Commented Aug 1, 2011 at 11:13
  • But my question is that right to do.? Commented Aug 1, 2011 at 11:13

1 Answer 1

1

Here, I am pasting an answer from already asked question Using request.setAttribute in a JSP page

No. Unfortunately the Request object is only available until the page finishes loading - once it's complete, you'll lose all values in it unless they've been stored somewhere.

If you want to persist attributes through requests you need to either:

1.Have a hidden input in your form, such as " />. This will then be available in the servlet as a request parameter.

2.Put it in the session (see request.getSession() - in a JSP this is available as simply session)

I recommend using the Session as it's easier to manage.

Sign up to request clarification or add additional context in comments.

2 Comments

How longer will this session persists.
It depends upon your configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.