aspose file tools*
The moose likes JSP and the fly likes request attribute NULL in JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "request attribute NULL in JSP page" Watch "request attribute NULL in JSP page" New topic
Author

request attribute NULL in JSP page

John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
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


www.cs-repository.info
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
Exactly how does
1. index.jsp "invoke" this servlet?
2. this servlet dispatch the request to result.jsp?

Bill
John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
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

Joined: Jan 10, 2002
Posts: 61241
    
  66

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
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

Joined: May 23, 2008
Posts: 215
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

Joined: Jan 10, 2002
Posts: 61241
    
  66

Nothing jumps out at me. Have you looked at the enumeration returned by getAttributeNames() to see what's there?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: May 23, 2008
Posts: 215


org.apache.catalina.ASYNC_SUPPORTED

is the output.
John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: May 23, 2008
Posts: 215
Oh... ok. Guess, the problem is solved then.

Thanks,
John
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: request attribute NULL in JSP page