• 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

Issue with Struts 2 Dispatcher Result

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

We are using Struts 2 Dispatcher Result to forward our request to some jsp page.

In struts.xml


Now we are able to see success.jsp but the request attributes we set are becoming null in success.jsp

We used dispatcher because we need the same request to be forwarded so that the request attributes we set can be retrieved in success.jsp But it is not happening and we are getting nulls instead.

Is there anything which needs to be taken care?

Thank you Chaitanya
 
Vivek Chaitanya
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Formatted the code...

 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us the action code as to how you are setting request attributes.

PS: The dispatcher result is the default result type if you extend the struts-default package...
 
Vivek Chaitanya
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,

Thanks for your reply.

We are setting request attributes using the standard request.setAttribute() method.

Regards
Chaitanya
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Besides that this isn't the canonical way to send data to a JSP in Struts 2...

Are you saying that you're calling request.setAttribute(...) in the method that then returns "success"? I don't see how that could fail to work.

By the way, "dispatcher" is the default result type, and the default param is "location"--your other result declarations are functionally equivalent to the "success" result you define by hand.
 
Vivek Chaitanya
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am calling request.setAttribute(...) in the method that returns success . i.e in execute method before returning success. I am not understanding why it is failing to set request attributes.
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us the code for that action which would make it easier to find out the problem...
 
Vivek Chaitanya
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In execute() method:




In JSP


 
Vivek Chaitanya
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And I am using dispatcher result type as below:

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you obtaining the request?

If you're doing this correctly, calling the action you think you are, and showing the result you think you are, there's no way this can fail. While I don't do it often (Struts 2 has a better way to pass data to a JSP, as I've already stated), it's unlikely to be an S2 issue.

It'd be so much easier if you just included all the relevant code and configuration at once.
 
Vivek Chaitanya
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi david, Thank you for your reply.

Struts 2 has a better way to pass data to a JSP, as I've already stated



Can you please let me know what is the better way to pass data to JSP?

Regards
Chaitanya
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The canonical Struts 2 way is to just make an action property, which are accessible via JSTL or the S2 tags via OGNL.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>How are you obtaining the request?
I was wondering the same thing. Probably Vivek tried Struts 1.X where it is available as part of the formal parameters of execute method

There should be a way to access request object anyway, IMHO, I know Struts 2 propose setting/passing values via properties, but to be able to set request in attribute is so much easier.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How on earth is request.setAttribute("name", "the name") easier than name = "the name"?
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic