Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To Pass the Request Scope to Another Class

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my ListThread class, I first retrieve some of the text fields; i.e., request.getParameter( ... );
Thereafter, I want to pass the request scope together with some parameters to another class; SiteUtil.java., for some further processing. This is what I do:

This is my SiteUtil.java:

Can I pass the request scope and save attributes in the scope this way?
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where you will use that Attribute set in second class. Request scope might not be right place instead HttpSession or ServletContext should be right place to setAtrribute & use it anywhere in session or application.
Hope this help.
[ April 09, 2004: Message edited by: Nehul Nalekar ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found it more flexible to create another collection from the request, and pass that around as in this example.

With this approach, you can test and use your helper classes outside the servlet environment. Furthermore, you can't keep a request object past the end of the request/response cycle, but you can save that Map for any purpose.
Bill
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah that make sense if you want to save request level info & don't want to save into session or application. You can also save into database but that depends on requirement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic