Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the lifespan of a request?

 
Per Jorgen Walstrom
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
I have the following actions


I call listDocuments.do and the resulting jsp-page lists some "channels" where it is possible to delete a chosen channel, by following a link to http://localhost:8080/saveChannel.do?method=delete&id=40278. ChannelAction extends DispatchAction. Now, in ChannelAction, I do a check if the channel can be deleted. If not, I do the following:



The thing is now, that listChannels.do does not seem to be able to display the errors. The attribute is gone from the request. Why is this? I have only done one request, as far as I can see. Does Struts consider going to another Action to be a completely new request?

any help would be appreciated!

cheers,
pj
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request is valid only for request time. If you want have data longer use another scope - session for example. I'm not sure how struts handle with request, but it is possible that after forward it creates new request.
 
Stefan Evans
Bartender
Posts: 1712
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request attributes last for the scope of a request.
Forward/include happens on the same request.
A redirect sends a response telling the browser to send a new request.

So request attributes are retained over a forward/include
Request attributes are lost if you issue a redirect.

Looking at your actionforward for /listChannels:
<forward name="forward" redirect="true" path="/channellist.jsp"/>

Solutions
- put the attribute in session
- don't redirect on a "listChannels" request
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic