• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

request attribute NULL in JSP page

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing jumps out at me. Have you looked at the enumeration returned by getAttributeNames() to see what's there?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh... ok. Guess, the problem is solved then.

Thanks,
John
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic