• Post Reply Bookmark Topic Watch Topic
  • New Topic

accessing context parameters with out using declaration tag

 
Naveen Megharaj
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
i have created a struts application, in which i have created 4 jsp pages. In 2nd and 3rd pages i m taking some data from the user and setting that data as context parameters using the HttpSession object. now i want to access these context parameters in the 4th jsp page but with out making use of the declaration tag(<%= java code %>). i wanted to know how can this be performed...??? any help is appreciated.....

thanks.
 
neil johnson
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can get it in two ways using EL

suppose you have an object named "testObj" in session scope which you have created using setAttribute

for getting it in jsp

1. ${testObj.name} -------- assuming that testObj has a property called name
2. ${sessionScope.testObj.name}


Finally include the below taglib directive
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
neil johnson wrote:Finally include the below taglib directive
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

The JSTL is not necessary in order to use the EL.

But, of course, you should be including it so that you can use the JSTL!
 
Naveen Megharaj
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i m new EL, till now i used to make use of scriptlet, declaration and expression tag in my jsp's.
my doubt is in order to make use of EL variable in my 4th jsp page, do i need to define then previously in my 2nd and 3rd jsp pages, where i m accepting the data from the user and setting that data as context parameters. actually i m setting user data as context parameters in my action classes.
thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"context parameter" is not the correct term; it's "scoped variable".

And it doesn't matter what has set up the scoped variable, the EL can access andy scoped variable.
 
neil johnson
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naveen Megharaj wrote: But i m new EL, till now i used to make use of scriptlet, declaration and expression tag in my jsp's.
my doubt is in order to make use of EL variable in my 4th jsp page, do i need to define then previously in my 2nd and 3rd jsp pages, where i m accepting the data from the user and setting that data as context parameters. actually i m setting user data as context parameters in my action classes.
thanks



not required. If you save it in HttpSession it is available throught out the session. so you can directly access it in the fourth jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that's exactly what he is talking about, just using the term "context parameter" incorrectly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!