• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request attribute NULL in JSP page

 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a index.jsp page where I set a request attribute


A servlet is invoked from index.jsp page which then dispatches it to result.jsp.
I tried printing the attribute value in result.jsp page.

But i get a null value!!

Regards,
John
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly how does
1. index.jsp "invoke" this servlet?
2. this servlet dispatch the request to result.jsp?

Bill
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Using form submission. I used a submit button.
2. Using RequestDispatcher.

There are other parameters and attributes that gets displayed on the result.jsp page without errors.


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two questions:
1) Why are you still using scriptlets?
2) Why bother setting a scoped variable for the context path when it's readily available already in the JSP?
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Two questions:
1) Why are you still using scriptlets?
2) Why bother setting a scoped variable for the context path when it's readily available already in the JSP?


Yes. It was just for my studying purpose. I would never use it in real situations.
But this is just an example I came up with to understand the subject better. (As a matter of fact, I have already started studying on JSTL and EL, today)
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any clue of what must be wrong here?
I checked the code again and again but nothing caught my eyes.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing jumps out at me. Have you looked at the enumeration returned by getAttributeNames() to see what's there?
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The process still isn't clear, but let me put down what I see through the fog:

(1) You have a JSP called index.jsp. In it you set some request attributes. It runs and generates some HTML which goes out to a browser.

(2) There's a submit button in that HTML, and when the user clicks it the browser generates a request which goes to a servlet.

(3) You are expecting the request attributes which you set on the first request to appear on that second request as well.

Do I have that right?
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


org.apache.catalina.ASYNC_SUPPORTED

is the output.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:The process still isn't clear, but let me put down what I see through the fog:
(1) You have a JSP called index.jsp. In it you set some request attributes. It runs and generates some HTML which goes out to a browser.
(2) There's a submit button in that HTML, and when the user clicks it the browser generates a request which goes to a servlet.
(3) You are expecting the request attributes which you set on the first request to appear on that second request as well.
Do I have that right?


Yes.
index.jsp(request attr set) > servlet (does nothing) > result.jsp(get request attr)
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Eipe wrote:
Paul Clapham wrote:The process still isn't clear, but let me put down what I see through the fog:
(1) You have a JSP called index.jsp. In it you set some request attributes. It runs and generates some HTML which goes out to a browser.
(2) There's a submit button in that HTML, and when the user clicks it the browser generates a request which goes to a servlet.
(3) You are expecting the request attributes which you set on the first request to appear on that second request as well.
Do I have that right?


Yes.
index.jsp(request attr set) > servlet (does nothing) > result.jsp(get request attr)


Then your expectation is wrong. Setting a request attribute only applies to the current request. Not to all requests which will be processed in the future.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh... ok. Guess, the problem is solved then.

Thanks,
John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic